TJaMStorageImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, 13-Oct-81 17:33:49
Bill Paxton, March 18, 1982 12:13 pm
Russ Atkinson, July 22, 1983 7:29 pm
Paul Rovner, August 18, 1983 4:02 pm
Michael Plass, February 14, 1985 1:02:02 pm PST
DIRECTORY
TJaMStorage USING [TextObject],
PrincOpsUtils USING [LongCopy],
UnsafeStorage USING [GetSystemUZone];
TJaMStorageImpl: PROGRAM
IMPORTS PrincOpsUtils, UnsafeStorage
EXPORTS TJaMStorage = {
zone: UNCOUNTED ZONE = UnsafeStorage.GetSystemUZone[];
Zone: PUBLIC PROC RETURNS[UNCOUNTED ZONE] = { RETURN[zone] };
pruning: BOOLEANFALSE; -- can turn this on someday
Prune: PUBLIC PROC = { IF pruning THEN NULL--UnsafeStorage.TrimUZone[zone]-- };
Text allocation
TextObject: TYPE = TJaMStorage.TextObject;
PrivateTextPut: PUBLIC PROC[t: POINTER TO TextObject, c: CHARACTER] = {
old: LONG STRING ← t.text;
new: LONG STRINGNIL;
length: CARDINAL ← t.len;
oldmax: CARDINAL ← t.max;
maxmax: CARDINAL = t.lim;
newmax: CARDINAL ← oldmax + MIN[oldmax/2,maxmax-oldmax];
IF NOT length<newmax THEN RETURN;
new ← zone.NEW[StringBody[newmax]];
PrincOpsUtils.LongCopy[from: @old.text, to: @new.text, nwords: (oldmax+1)/2];
IF old#t.cache THEN zone.FREE[@old];
t.text ← new; t.max ← new.maxlength;
new[length] ← c; t.len ← length + 1;
};
PrivateTextFree: PUBLIC PROC[t: POINTER TO TextObject] = {
IF t.text#t.cache THEN zone.FREE[@t.text];
};
}.