Keywords as basic scalar type
Script enhancements
This commit is contained in:
@@ -34,7 +34,7 @@ type
|
||||
class var
|
||||
FLock: TSpinLock;
|
||||
class var
|
||||
FRegistry: TDictionary<string, IKeyword>;
|
||||
FRegistry: TDictionary<string, Integer>;
|
||||
class var
|
||||
FReverseMap: TList<IKeyword>; // Use TList
|
||||
class constructor Create;
|
||||
@@ -116,7 +116,7 @@ end;
|
||||
class constructor TKeywordRegistry.Create;
|
||||
begin
|
||||
FLock := TSpinLock.Create(false);
|
||||
FRegistry := TDictionary<string, IKeyword>.Create;
|
||||
FRegistry := TDictionary<string, Integer>.Create;
|
||||
FReverseMap := TList<IKeyword>.Create;
|
||||
|
||||
Intern('false');
|
||||
@@ -135,24 +135,25 @@ begin
|
||||
try
|
||||
// Check bounds
|
||||
if (AIdx >= 0) and (AIdx < FReverseMap.Count) then
|
||||
Result := FReverseMap[AIdx].Name
|
||||
else
|
||||
Result := ''; // Return empty for safety
|
||||
Result := FReverseMap[AIdx].Name;
|
||||
finally
|
||||
FLock.Exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TKeywordRegistry.Intern(const AName: string): IKeyword;
|
||||
var
|
||||
idx: Integer;
|
||||
begin
|
||||
FLock.Enter;
|
||||
try
|
||||
if not FRegistry.TryGetValue(AName, Result) then
|
||||
if not FRegistry.TryGetValue(AName, idx) then
|
||||
begin
|
||||
Result := TKeyword.Create(AName, FRegistry.Count);
|
||||
FReverseMap.Add(Result); // Add to reverse map (Idx -> Interface)
|
||||
FRegistry.Add(AName, Result); // Add to forward map (Name -> Interface)
|
||||
end;
|
||||
FRegistry.Add(AName, FReverseMap.Add(Result));
|
||||
end
|
||||
else
|
||||
Result := FReverseMap[idx];
|
||||
finally
|
||||
FLock.Exit;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user