From 815a8aa373af362f9ade15bf0177c97cb70ef23e Mon Sep 17 00:00:00 2001 From: tigrazone Date: Mon, 30 Oct 2017 19:39:44 +0200 Subject: [PATCH 01/13] Add files via upload change hash function to simple and fast *31 function 22% speedup --- src/BESENHashUtils.pas | 13 +++++++++++++ src/thrHashUtils.pas | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/thrHashUtils.pas diff --git a/src/BESENHashUtils.pas b/src/BESENHashUtils.pas index cc0ff21..e70838f 100644 --- a/src/BESENHashUtils.pas +++ b/src/BESENHashUtils.pas @@ -31,16 +31,28 @@ unit BESENHashUtils; {$i BESEN.inc} +{$define THRhash} + interface uses BESENConstants,BESENTypes; + +{$ifdef THRhash} +uses thrHashUtils; +{$endif} + function BESENHashKey(const Key:TBESENString):TBESENHash; function BESENDoubleHash(Hash:TBESENHash):TBESENHash; implementation function BESENHashKey(const Key:TBESENString):TBESENHash; +{$ifdef THRhash} +begin + result:=thrHashKey(key); +end; +{$else} {$ifdef PurePascal} var i,h:longword; begin @@ -146,6 +158,7 @@ function BESENHashKey(const Key:TBESENString):TBESENHash; {$endif} {$endif} {$endif} +{$endif} function BESENDoubleHash(Hash:TBESENHash):TBESENHash; begin diff --git a/src/thrHashUtils.pas b/src/thrHashUtils.pas new file mode 100644 index 0000000..d99cae7 --- /dev/null +++ b/src/thrHashUtils.pas @@ -0,0 +1,42 @@ +unit thrHashUtils; + +interface + +uses BESENConstants,BESENTypes; + +function thrHashKey(const Key:TBESENString):TBESENHash; + +implementation + +(* +implementation of h*31 + *s simple and fast hashing function + +uint32_t X31_hash_string(const char *s) +{ + + khint_t h = *s; + for (++s ; *s; ++s) h = (h << 5) - h + *s; + return h; +} + +*) + + +function thrHashKey(const Key:TBESENString):TBESENHash; +var i,h:longword; +begin + if length(key)<1 then + begin + result:=0; + exit; + end; + + h:=ord(Key[1]); + for i:=2 to length(Key) do begin + h:=(h shl 5) - h + ord(Key[i]); + end; + + result:=h; +end; + +end. From 293660bb5760aba35122f85dcfa21a48f52417bf Mon Sep 17 00:00:00 2001 From: tigrazone Date: Mon, 30 Oct 2017 19:41:45 +0200 Subject: [PATCH 02/13] Add files via upload added benchmark for generate 5000 perfect numbers --- examplescripts/perfect5000.js | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examplescripts/perfect5000.js diff --git a/examplescripts/perfect5000.js b/examplescripts/perfect5000.js new file mode 100644 index 0000000..4e5a9d8 --- /dev/null +++ b/examplescripts/perfect5000.js @@ -0,0 +1,42 @@ + +// Some simple testing of new, eval and some string stuff. + +// constructor -- expression array initialization +function ExprArray(n,v) +{ + // Initializes n values to v coerced to a string. + for (var i = 0; i < n; i++) { + this[i] = "" + v; + } +} + + +// Print the perfect numbers up to n and the sum expression for n's divisors. +function perfect(n) +{ + trace("The perfect numbers up to " + n + " are:"); + + // We build sumOfDivisors[i] to hold a string expression for + // the sum of the divisors of i, excluding i itself. + var sumOfDivisors = new ExprArray(n+1,1); + for (var divisor = 2; divisor <= n; divisor++) { + for (var j = divisor + divisor; j <= n; j += divisor) { + sumOfDivisors[j] += " + " + divisor; + } + // At this point everything up to 'divisor' has its sumOfDivisors + // expression calculated, so we can determine whether it's perfect + // already by evaluating. + if (eval(sumOfDivisors[divisor]) == divisor) { + trace("" + divisor + " = " + sumOfDivisors[divisor]); + } + } + trace("That's all."); +} + + +trace("\nA number is 'perfect' if it is equal to the sum of its"); +trace("divisors (excluding itself).\n"); +var st=(new Date()).valueOf(); +perfect(5000); + var et=(new Date()).valueOf(); + trace(et-st,' milliseconds'); \ No newline at end of file From 82d2a92c19ac62f325dade46b4efc28756c16929 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Mon, 30 Oct 2017 19:46:07 +0200 Subject: [PATCH 03/13] Add files via upload fix compile error --- src/BESENHashUtils.pas | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BESENHashUtils.pas b/src/BESENHashUtils.pas index e70838f..de269af 100644 --- a/src/BESENHashUtils.pas +++ b/src/BESENHashUtils.pas @@ -35,12 +35,12 @@ interface -uses BESENConstants,BESENTypes; - - +uses BESENConstants,BESENTypes {$ifdef THRhash} -uses thrHashUtils; +,thrHashUtils {$endif} +; + function BESENHashKey(const Key:TBESENString):TBESENHash; function BESENDoubleHash(Hash:TBESENHash):TBESENHash; From 63e49877f1f8b38b8f3a3d6b69b5c28e177b8675 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Mon, 30 Oct 2017 20:21:31 +0200 Subject: [PATCH 04/13] Add files via upload really up to 3% speedup --- src/BESENHashUtils.pas | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/BESENHashUtils.pas b/src/BESENHashUtils.pas index de269af..65b87dd 100644 --- a/src/BESENHashUtils.pas +++ b/src/BESENHashUtils.pas @@ -31,15 +31,10 @@ unit BESENHashUtils; {$i BESEN.inc} -{$define THRhash} interface -uses BESENConstants,BESENTypes -{$ifdef THRhash} -,thrHashUtils -{$endif} -; +uses BESENConstants,BESENTypes; function BESENHashKey(const Key:TBESENString):TBESENHash; @@ -49,8 +44,20 @@ implementation function BESENHashKey(const Key:TBESENString):TBESENHash; {$ifdef THRhash} +var i,h:longword; begin - result:=thrHashKey(key); + if length(key)<1 then + begin + result:=0; + exit; + end; + + h:=ord(Key[1]); + for i:=2 to length(Key) do begin + h:=(h shl 5) - h + ord(Key[i]); + end; + + result:=h; end; {$else} {$ifdef PurePascal} From cc46dd33ee3cc37a8f1ed5a392a999b67e562216 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Mon, 30 Oct 2017 20:53:28 +0200 Subject: [PATCH 05/13] faster version with new hash function compact code, one module uses. speed up really to 22% --- src/BESENHashUtils.pas | 24 ++++++++---------------- src/thrHashUtils.pas | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/BESENHashUtils.pas b/src/BESENHashUtils.pas index 65b87dd..b4f4ac6 100644 --- a/src/BESENHashUtils.pas +++ b/src/BESENHashUtils.pas @@ -30,11 +30,15 @@ *******************************************************************************) unit BESENHashUtils; {$i BESEN.inc} - +{$define THRhash} interface -uses BESENConstants,BESENTypes; +uses BESENConstants,BESENTypes +{$ifdef THRhash} +,thrHashUtils +{$endif} +; function BESENHashKey(const Key:TBESENString):TBESENHash; @@ -44,20 +48,8 @@ implementation function BESENHashKey(const Key:TBESENString):TBESENHash; {$ifdef THRhash} -var i,h:longword; -begin - if length(key)<1 then - begin - result:=0; - exit; - end; - - h:=ord(Key[1]); - for i:=2 to length(Key) do begin - h:=(h shl 5) - h + ord(Key[i]); - end; - - result:=h; +begin + result:=thrHashKey(key); end; {$else} {$ifdef PurePascal} diff --git a/src/thrHashUtils.pas b/src/thrHashUtils.pas index d99cae7..83c8f83 100644 --- a/src/thrHashUtils.pas +++ b/src/thrHashUtils.pas @@ -18,7 +18,7 @@ implementation of h*31 + *s simple and fast hashing function for (++s ; *s; ++s) h = (h << 5) - h + *s; return h; } - + *) From b03b459050c8747f1e50bf6f881c2fa6af3c70dc Mon Sep 17 00:00:00 2001 From: tigrazone Date: Mon, 30 Oct 2017 23:18:20 +0200 Subject: [PATCH 06/13] binary search in FindKeyword with hashed string calc hash and compare with hashed values --- src/BESENConstants.pas | 5 ++ src/BESENHashUtils.pas | 1 - src/BESENLexer.pas | 103 ++++++++++++++++++++++++++++++++++++++++- src/thrHashUtils.pas | 2 +- 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/src/BESENConstants.pas b/src/BESENConstants.pas index 9200bd3..4116197 100644 --- a/src/BESENConstants.pas +++ b/src/BESENConstants.pas @@ -31,6 +31,11 @@ unit BESENConstants; {$i BESEN.inc} + +{$define THRhash } + + + interface uses Math; diff --git a/src/BESENHashUtils.pas b/src/BESENHashUtils.pas index b4f4ac6..52642bd 100644 --- a/src/BESENHashUtils.pas +++ b/src/BESENHashUtils.pas @@ -30,7 +30,6 @@ *******************************************************************************) unit BESENHashUtils; {$i BESEN.inc} -{$define THRhash} interface diff --git a/src/BESENLexer.pas b/src/BESENLexer.pas index 27242c6..e637d96 100644 --- a/src/BESENLexer.pas +++ b/src/BESENLexer.pas @@ -161,13 +161,18 @@ TBESENLexer=class(TBESENBaseObject) implementation -uses {$ifdef BESENEmbarcaderoNextGen}System.Character,{$endif}BESEN,BESENRegExp,BESENErrors,BESENNumberUtils; +uses {$ifdef BESENEmbarcaderoNextGen}System.Character,{$endif}BESEN,BESENRegExp,BESENErrors,BESENNumberUtils +{$ifdef THRhash} +,thrHashUtils +{$endif} +; type TKeywordToken=ltkBREAK..ltkYIELD; TKeyword=TKeywordToken; TKeywords=array of TKeyword; + TKeywordsHash=array of TBESENHash; const KeywordNames:array[TKeywordToken] of TBESENUTF16STRING= (// Used keywords @@ -189,6 +194,10 @@ implementation Keywords:TKeywords=nil; +{$ifdef THRhash} + KeywordsHash:TKeywordsHash=nil; +{$endif} + constructor TBESENLexer.Create(AInstance:TObject); begin inherited Create(AInstance); @@ -550,12 +559,61 @@ procedure TBESENLexer.GetToken(var AResult:TBESENLexerToken); s:=''; end; + + function FindKeyword(const Name:TBESENUTF16STRING):TBESENLexerTokenType; var LowIndex,HighIndex,MiddleIndex:integer; + {$ifdef THRhash} + aHash: TBESENHash; + {$endif} begin result:=lttIDENTIFIER; LowIndex:=0; HighIndex:=length(Keywords)-1; + + {$ifdef THRhash} + aHash:=thrHashKey(Name); + while LowIndex<=HighIndex do begin + case (HighIndex-LowIndex)+1 of + 1:begin + if KeywordsHash[ + Keywords[LowIndex] + ]=aHash then begin + result:=Keywords[LowIndex]; + end; + end; + 2:begin + if KeywordsHash[ + Keywords[LowIndex] + ]=aHash then begin + result:=Keywords[LowIndex]; + end else if KeywordsHash[ + Keywords[HighIndex] + ]=aHash then begin + result:=Keywords[HighIndex]; + end; + end; + else begin + MiddleIndex:=(LowIndex+HighIndex) div 2; + if KeywordsHash[ + Keywords[MiddleIndex] + ]=aHash then begin + result:=Keywords[MiddleIndex]; + end else if LowIndex<>HighIndex then begin + if KeywordsHash[ + Keywords[MiddleIndex] + ]>aHash then begin + HighIndex:=MiddleIndex-1; + end else begin + LowIndex:=MiddleIndex+1; + end; + continue; + end; + end; + end; + break; + end; + {$else} while LowIndex<=HighIndex do begin case (HighIndex-LowIndex)+1 of 1:begin @@ -586,6 +644,8 @@ procedure TBESENLexer.GetToken(var AResult:TBESENLexerToken); end; break; end; + + {$endif} end; begin AResult.Name:=''; @@ -1370,13 +1430,47 @@ procedure InitKeywords; var kt:TKeywordToken; i:integer; k:TKeyword; + sz:integer; begin - SetLength(Keywords,(integer(high(TKeywordToken))-integer(low(TKeywordToken)))+1); + sz:=(integer(high(TKeywordToken))-integer(low(TKeywordToken)))+1; + + SetLength(Keywords,sz); + +{$ifdef THRhash} + //tigra: add hash calc of keys + SetLength(KeywordsHash,sz); +{$endif} + i:=0; for kt:=low(TKeywordToken) to high(TKeywordToken) do begin Keywords[i]:=kt; + +{$ifdef THRhash} + //tigra: calc hash and store + KeywordsHash[i]:=thrHashKey(KeywordNames[kt]); + {$endif} inc(i); end; + + //sort keywords by keywordNames + + {$ifdef THRhash} + i:=0; + while (i+1)KeywordsHash[Keywords[i+1]] then begin + k:=Keywords[i]; + Keywords[i]:=Keywords[i+1]; + Keywords[i+1]:=k; + if i>0 then begin + dec(i); + end else begin + inc(i); + end; + end else begin + inc(i); + end; + end; + {$else} i:=0; while (i+1)KeywordNames[Keywords[i+1]] then begin @@ -1392,11 +1486,16 @@ procedure InitKeywords; inc(i); end; end; + {$endif} + end; procedure DoneKeywords; begin SetLength(Keywords,0); +{$ifdef THRhash} + SetLength(KeywordsHash,0); +{$endif} end; procedure InitBESEN; diff --git a/src/thrHashUtils.pas b/src/thrHashUtils.pas index 83c8f83..2124c69 100644 --- a/src/thrHashUtils.pas +++ b/src/thrHashUtils.pas @@ -2,7 +2,7 @@ interface -uses BESENConstants,BESENTypes; +uses BESENTypes; function thrHashKey(const Key:TBESENString):TBESENHash; From bd225cd988b70b7c2618b781980faebc7965ff19 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 00:37:42 +0200 Subject: [PATCH 07/13] hashed!!!!! --- src/BESENConstants.pas | 2 +- src/BESENParser.pas | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/BESENConstants.pas b/src/BESENConstants.pas index 4116197..5686eee 100644 --- a/src/BESENConstants.pas +++ b/src/BESENConstants.pas @@ -32,7 +32,7 @@ {$i BESEN.inc} -{$define THRhash } +{$define THRhash} diff --git a/src/BESENParser.pas b/src/BESENParser.pas index 3b6e486..7fe3f65 100644 --- a/src/BESENParser.pas +++ b/src/BESENParser.pas @@ -295,7 +295,9 @@ function TBESENParser.Parse(IsFunction,IsJSON:boolean):TBESENASTNode; OldToken:=CurrentToken; NextToken; if NextIsSemicolon then begin - if (length(OldToken.StringValue)=10) and (copy(Lexer.Source,OldToken.OldPosition,10)='use strict') then begin + if (length(OldToken.StringValue)=10) then begin + + if (copy(Lexer.Source,OldToken.OldPosition,10)='use strict') then begin if UseStrictAlreadyParsed then begin AddWarning('"use strict"/''use strict'' already seen!'); end else begin @@ -311,6 +313,8 @@ function TBESENParser.Parse(IsFunction,IsJSON:boolean):TBESENASTNode; end; end; end; + + end; FirstDirective:=false; end else begin IsDirectivePrologue:=false; From 6aa6e74887f3a3ba9918f80351c2074199889a4b Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 01:26:43 +0200 Subject: [PATCH 08/13] one more hashing --- src/BESENDeclarativeEnvironmentRecord.pas | 44 ++++++++++++++++++++++- src/BESENHashMap.pas | 19 ++++++++++ src/BESENObject.pas | 12 +++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/BESENDeclarativeEnvironmentRecord.pas b/src/BESENDeclarativeEnvironmentRecord.pas index b3c8e72..583f98e 100644 --- a/src/BESENDeclarativeEnvironmentRecord.pas +++ b/src/BESENDeclarativeEnvironmentRecord.pas @@ -235,7 +235,25 @@ procedure TBESENDeclarativeEnvironmentRecord.GrowAndRehashIfNeeded; end; function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENDeclarativeEnvironmentRecordHashItem; +var aHash:TBESENHash; begin + aHash:=Hash; + +{$ifdef THRhash} + if assigned(LastUsedItem) and (LastUsedItem^.Hash=aHash) then begin + result:=LastUsedItem; + Hash:=result^.Hash; + end else begin + if Hash=0 then begin + Hash:=BESENHashKey(Key); + end; + Hash:=Hash and HashSizeMask; + result:=HashBuckets[Hash].HashFirst; + while assigned(result) and (result^.Hash<>aHash) do begin + result:=result^.HashNext; + end; + end; + {$else} if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin result:=LastUsedItem; Hash:=result^.Hash; @@ -249,6 +267,8 @@ function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:T result:=result^.HashNext; end; end; + {$endif} + if assigned(result) then begin LastUsedItem:=result; if HashBuckets[Hash].HashFirst<>result then begin @@ -269,28 +289,50 @@ function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:T end; function TBESENDeclarativeEnvironmentRecord.NewKey(const Key:TBESENString;Force:boolean=false;Hash:TBESENHash=0):PBESENDeclarativeEnvironmentRecordHashItem; +var aHash:TBESENHash; begin + aHash:=Hash; + if Force then begin result:=nil; + if Hash=0 then begin Hash:=BESENHashKey(Key); + aHash:=Hash; end; + Hash:=Hash and HashSizeMask; - end else if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin + end else + {$ifdef THRhash} + if assigned(LastUsedItem) and (LastUsedItem^.Hash=aHash) + {$else} + if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) + {$endif} + then begin result:=LastUsedItem; Hash:=result^.Hash; end else begin if Hash=0 then begin Hash:=BESENHashKey(Key); + aHash:=Hash; end; Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; if not assigned(result) then begin inc(HashBucketsUsed); end; + + {$ifdef THRhash} + while assigned(result) and (result^.Hash<>aHash) do begin + result:=result^.HashNext; + end; + {$else} while assigned(result) and (result^.Key<>Key) do begin result:=result^.HashNext; end; + {$endif} + + end; if not assigned(result) then begin inc(HashedItems); diff --git a/src/BESENHashMap.pas b/src/BESENHashMap.pas index 637ddde..b152ab9 100644 --- a/src/BESENHashMap.pas +++ b/src/BESENHashMap.pas @@ -175,19 +175,38 @@ procedure TBESENHashMap.GrowAndRehashIfNeeded; end; function TBESENHashMap.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENHashMapItem; +var aHash:TBESENHash; begin +aHash:=Hash; + + {$ifdef THRhash} + if assigned(LastUsedItem) and (LastUsedItem^.Hash=aHash) then begin + {$else} if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin + {$endif} + result:=LastUsedItem; Hash:=result^.Hash; + aHash:=Hash; end else begin if Hash=0 then begin Hash:=BESENHashKey(Key); + aHash:=Hash; end; Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; + + {$ifdef THRhash} + while assigned(result) and (result^.Hash<>aHash) do begin + result:=result^.HashNext; + end; + {$else} while assigned(result) and (result^.Key<>Key) do begin result:=result^.HashNext; end; + {$endif} + + end; if assigned(result) then begin LastUsedItem:=result; diff --git a/src/BESENObject.pas b/src/BESENObject.pas index 51460af..09b27fa 100644 --- a/src/BESENObject.pas +++ b/src/BESENObject.pas @@ -822,19 +822,31 @@ function TBESENObjectPropertyContainer.Put(const Key:TBESENString;Hash:TBESENHas end; function TBESENObjectPropertyContainer.Get(const Key:TBESENString;Hash:TBESENHash=0):TBESENObjectProperty; +var aHash:TBESENHash; begin + aHash:=Hash; if assigned(LastUsedItem) and (LastUsedItem.Key=Key) then begin result:=LastUsedItem; Hash:=result.Hash; + aHash:=Hash; end else begin IF Hash=0 then begin Hash:=BESENHashKey(Key); + aHash:=Hash; end; Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; + + {$ifdef THRhash} + while assigned(result) and (result.Hash<>aHash) do begin + result:=result.HashNext; + end; + {$else} while assigned(result) and (result.Key<>Key) do begin result:=result.HashNext; end; + {$endif} + end; if assigned(result) then begin LastUsedItem:=result; From a1326fcc1b35dca43c0f97f6e063a943cd946d4d Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 01:59:04 +0200 Subject: [PATCH 09/13] separate hashed --- src/BESENConstants.pas | 1 + src/BESENDeclarativeEnvironmentRecord.pas | 44 +---------------------- src/BESENHashMap.pas | 8 ++--- src/BESENLexer.pas | 14 ++++---- src/BESENObject.pas | 12 ------- 5 files changed, 11 insertions(+), 68 deletions(-) diff --git a/src/BESENConstants.pas b/src/BESENConstants.pas index 5686eee..3b88c45 100644 --- a/src/BESENConstants.pas +++ b/src/BESENConstants.pas @@ -33,6 +33,7 @@ {$define THRhash} +{$define THRhash2} diff --git a/src/BESENDeclarativeEnvironmentRecord.pas b/src/BESENDeclarativeEnvironmentRecord.pas index 583f98e..b3c8e72 100644 --- a/src/BESENDeclarativeEnvironmentRecord.pas +++ b/src/BESENDeclarativeEnvironmentRecord.pas @@ -235,25 +235,7 @@ procedure TBESENDeclarativeEnvironmentRecord.GrowAndRehashIfNeeded; end; function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENDeclarativeEnvironmentRecordHashItem; -var aHash:TBESENHash; begin - aHash:=Hash; - -{$ifdef THRhash} - if assigned(LastUsedItem) and (LastUsedItem^.Hash=aHash) then begin - result:=LastUsedItem; - Hash:=result^.Hash; - end else begin - if Hash=0 then begin - Hash:=BESENHashKey(Key); - end; - Hash:=Hash and HashSizeMask; - result:=HashBuckets[Hash].HashFirst; - while assigned(result) and (result^.Hash<>aHash) do begin - result:=result^.HashNext; - end; - end; - {$else} if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin result:=LastUsedItem; Hash:=result^.Hash; @@ -267,8 +249,6 @@ function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:T result:=result^.HashNext; end; end; - {$endif} - if assigned(result) then begin LastUsedItem:=result; if HashBuckets[Hash].HashFirst<>result then begin @@ -289,50 +269,28 @@ function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:T end; function TBESENDeclarativeEnvironmentRecord.NewKey(const Key:TBESENString;Force:boolean=false;Hash:TBESENHash=0):PBESENDeclarativeEnvironmentRecordHashItem; -var aHash:TBESENHash; begin - aHash:=Hash; - if Force then begin result:=nil; - if Hash=0 then begin Hash:=BESENHashKey(Key); - aHash:=Hash; end; - Hash:=Hash and HashSizeMask; - end else - {$ifdef THRhash} - if assigned(LastUsedItem) and (LastUsedItem^.Hash=aHash) - {$else} - if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) - {$endif} - then begin + end else if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin result:=LastUsedItem; Hash:=result^.Hash; end else begin if Hash=0 then begin Hash:=BESENHashKey(Key); - aHash:=Hash; end; Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; if not assigned(result) then begin inc(HashBucketsUsed); end; - - {$ifdef THRhash} - while assigned(result) and (result^.Hash<>aHash) do begin - result:=result^.HashNext; - end; - {$else} while assigned(result) and (result^.Key<>Key) do begin result:=result^.HashNext; end; - {$endif} - - end; if not assigned(result) then begin inc(HashedItems); diff --git a/src/BESENHashMap.pas b/src/BESENHashMap.pas index b152ab9..3063d94 100644 --- a/src/BESENHashMap.pas +++ b/src/BESENHashMap.pas @@ -175,29 +175,25 @@ procedure TBESENHashMap.GrowAndRehashIfNeeded; end; function TBESENHashMap.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENHashMapItem; -var aHash:TBESENHash; begin -aHash:=Hash; {$ifdef THRhash} - if assigned(LastUsedItem) and (LastUsedItem^.Hash=aHash) then begin + if assigned(LastUsedItem) and (LastUsedItem^.Hash=Hash) then begin {$else} if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin {$endif} result:=LastUsedItem; Hash:=result^.Hash; - aHash:=Hash; end else begin if Hash=0 then begin Hash:=BESENHashKey(Key); - aHash:=Hash; end; Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; {$ifdef THRhash} - while assigned(result) and (result^.Hash<>aHash) do begin + while assigned(result) and (result^.Hash<>Hash) do begin result:=result^.HashNext; end; {$else} diff --git a/src/BESENLexer.pas b/src/BESENLexer.pas index e637d96..e8c2e69 100644 --- a/src/BESENLexer.pas +++ b/src/BESENLexer.pas @@ -194,7 +194,7 @@ implementation Keywords:TKeywords=nil; -{$ifdef THRhash} +{$ifdef THRhash2} KeywordsHash:TKeywordsHash=nil; {$endif} @@ -563,7 +563,7 @@ procedure TBESENLexer.GetToken(var AResult:TBESENLexerToken); function FindKeyword(const Name:TBESENUTF16STRING):TBESENLexerTokenType; var LowIndex,HighIndex,MiddleIndex:integer; - {$ifdef THRhash} + {$ifdef THRhash2} aHash: TBESENHash; {$endif} begin @@ -571,7 +571,7 @@ procedure TBESENLexer.GetToken(var AResult:TBESENLexerToken); LowIndex:=0; HighIndex:=length(Keywords)-1; - {$ifdef THRhash} + {$ifdef THRhash2} aHash:=thrHashKey(Name); while LowIndex<=HighIndex do begin case (HighIndex-LowIndex)+1 of @@ -1436,7 +1436,7 @@ procedure InitKeywords; SetLength(Keywords,sz); -{$ifdef THRhash} +{$ifdef THRhash2} //tigra: add hash calc of keys SetLength(KeywordsHash,sz); {$endif} @@ -1445,7 +1445,7 @@ procedure InitKeywords; for kt:=low(TKeywordToken) to high(TKeywordToken) do begin Keywords[i]:=kt; -{$ifdef THRhash} +{$ifdef THRhash2} //tigra: calc hash and store KeywordsHash[i]:=thrHashKey(KeywordNames[kt]); {$endif} @@ -1454,7 +1454,7 @@ procedure InitKeywords; //sort keywords by keywordNames - {$ifdef THRhash} + {$ifdef THRhash2} i:=0; while (i+1)KeywordsHash[Keywords[i+1]] then begin @@ -1493,7 +1493,7 @@ procedure InitKeywords; procedure DoneKeywords; begin SetLength(Keywords,0); -{$ifdef THRhash} +{$ifdef THRhash2} SetLength(KeywordsHash,0); {$endif} end; diff --git a/src/BESENObject.pas b/src/BESENObject.pas index 09b27fa..51460af 100644 --- a/src/BESENObject.pas +++ b/src/BESENObject.pas @@ -822,31 +822,19 @@ function TBESENObjectPropertyContainer.Put(const Key:TBESENString;Hash:TBESENHas end; function TBESENObjectPropertyContainer.Get(const Key:TBESENString;Hash:TBESENHash=0):TBESENObjectProperty; -var aHash:TBESENHash; begin - aHash:=Hash; if assigned(LastUsedItem) and (LastUsedItem.Key=Key) then begin result:=LastUsedItem; Hash:=result.Hash; - aHash:=Hash; end else begin IF Hash=0 then begin Hash:=BESENHashKey(Key); - aHash:=Hash; end; Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; - - {$ifdef THRhash} - while assigned(result) and (result.Hash<>aHash) do begin - result:=result.HashNext; - end; - {$else} while assigned(result) and (result.Key<>Key) do begin result:=result.HashNext; end; - {$endif} - end; if assigned(result) then begin LastUsedItem:=result; From fce1e65264ea1cf5eef560439dcd052a97b40a79 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 07:35:28 +0200 Subject: [PATCH 10/13] small optimiZations --- src/BESENDateUtils.pas | 7 ++++--- src/BESENDeclarativeEnvironmentRecord.pas | 4 +++- src/BESENLexer.pas | 12 ++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/BESENDateUtils.pas b/src/BESENDateUtils.pas index 6d06de4..e10594e 100644 --- a/src/BESENDateUtils.pas +++ b/src/BESENDateUtils.pas @@ -632,7 +632,7 @@ function BESENParseISOTime(s:TBESENString):TBESENDate; result:=double(pointer(@BESENDoubleNaN)^); exit; end; - result:=BESENMakeDay(StrToIntDef(copy(ss,1,4),0),StrToIntDef(copy(ss,5+(1*Offset),2),0),StrToIntDef(copy(ss,7+(2*Offset),2),0)); + result:=BESENMakeDay(StrToIntDef(copy(ss,1,4),0),StrToIntDef(copy(ss,5+(Offset),2),0),StrToIntDef(copy(ss,7+(Offset+Offset),2),0)); end; function ParseTime(const ss:TBESENString):TBESENDate; var s,ms:TBESENString; @@ -667,9 +667,10 @@ function BESENParseISOTime(s:TBESENString):TBESENDate; exit; end; Hours:=StrToIntDef(copy(s,1,2),100); - Minutes:=StrToIntDef(copy(s,3+(1*Offset),2),100); + //Minutes:=StrToIntDef(copy(s,3+(1*Offset),2),100); + Minutes:=StrToIntDef(copy(s,3+(Offset),2),100); if WithSeconds then begin - Seconds:=StrToIntDef(copy(s,5+(2*Offset),2),100); + Seconds:=StrToIntDef(copy(s,5+(Offset+Offset),2),100); end else begin Seconds:=0; if length(ms)>0 then begin diff --git a/src/BESENDeclarativeEnvironmentRecord.pas b/src/BESENDeclarativeEnvironmentRecord.pas index b3c8e72..4526215 100644 --- a/src/BESENDeclarativeEnvironmentRecord.pas +++ b/src/BESENDeclarativeEnvironmentRecord.pas @@ -215,7 +215,9 @@ procedure TBESENDeclarativeEnvironmentRecord.GrowAndRehashIfNeeded; HashBucketsUsed:=0; Item:=First; while assigned(Item) do begin + Hash:=BESENHashKey(Item^.Key) and HashSizeMask; + Item^.Hash:=Hash; if assigned(HashBuckets[Hash].HashLast) then begin HashBuckets[Hash].HashLast^.HashNext:=Item; @@ -243,7 +245,7 @@ function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:T if Hash=0 then begin Hash:=BESENHashKey(Key); end; - Hash:=Hash and HashSizeMask; +Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; while assigned(result) and (result^.Key<>Key) do begin result:=result^.HashNext; diff --git a/src/BESENLexer.pas b/src/BESENLexer.pas index e8c2e69..6d26dfe 100644 --- a/src/BESENLexer.pas +++ b/src/BESENLexer.pas @@ -565,6 +565,7 @@ procedure TBESENLexer.GetToken(var AResult:TBESENLexerToken); var LowIndex,HighIndex,MiddleIndex:integer; {$ifdef THRhash2} aHash: TBESENHash; + aHash1: TBESENHash; {$endif} begin result:=lttIDENTIFIER; @@ -595,14 +596,13 @@ procedure TBESENLexer.GetToken(var AResult:TBESENLexerToken); end; else begin MiddleIndex:=(LowIndex+HighIndex) div 2; - if KeywordsHash[ - Keywords[MiddleIndex] - ]=aHash then begin + + aHash1 :=KeywordsHash[ Keywords[MiddleIndex] ]; + + if aHash1=aHash then begin result:=Keywords[MiddleIndex]; end else if LowIndex<>HighIndex then begin - if KeywordsHash[ - Keywords[MiddleIndex] - ]>aHash then begin + if aHash1>aHash then begin HighIndex:=MiddleIndex-1; end else begin LowIndex:=MiddleIndex+1; From 164f9d85183f9bf77b5b2375066fa109be7ce198 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 08:27:07 +0200 Subject: [PATCH 11/13] last speedups and change copy of standard functions to original --- src/BESENStringUtils.pas | 107 ++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/src/BESENStringUtils.pas b/src/BESENStringUtils.pas index 52a88e0..5741b17 100644 --- a/src/BESENStringUtils.pas +++ b/src/BESENStringUtils.pas @@ -761,7 +761,8 @@ function BESENEncodeBase64(s:TBESENANSISTRING):TBESENANSISTRING; if l>1 then begin SetLength(result,l-1); end else begin - result:=BESENAnsiTrim(result); + //result:=BESENAnsiTrim(result); + result:=Trim(result); end; end; end; @@ -782,7 +783,7 @@ function BESENDequote(s:TBESENANSISTRING):TBESENANSISTRING; s:=s+#13#10; end; end; - p:=BESENANSIPosChar('=',s); + p:=Pos('=',s); while p>0 do begin encode:=ansichar(byte((pos(s[p+1],hexa) shl 4) or pos(s[p+2],hexa))); if encode=#0 then begin @@ -790,13 +791,13 @@ function BESENDequote(s:TBESENANSISTRING):TBESENANSISTRING; end; result:=result+copy(s,1,p-1)+encode; delete(s,1,p+2); - p:=BESENANSIPosChar('=',s); + p:=Pos('=',s); end; result:=result+s; - p:=BESENANSIPosChar('_',result); + p:=Pos('_',result); while p>0 do begin result[p]:=' '; - p:=BESENANSIPosChar('_',result); + p:=Pos('_',result); end; end; end; @@ -1190,7 +1191,7 @@ function BESENEncodeString(Value:TBESENANSISTRING;CharFrom:TBESENCharset;CharTo: inc(i); if c='-' then begin break; - end else if (c='=') or (BESENANSIPosChar(c,BESENBase64Chars)<1) then begin + end else if (c='=') or (Pos(c,BESENBase64Chars)<1) then begin dec(i); break; end; @@ -1243,7 +1244,7 @@ function BESENEncodeString(Value:TBESENANSISTRING;CharFrom:TBESENCharset;CharTo: end; end; s:=BESENEncodeBase64(s); - j:=BESENANSIPosChar('=',s); + j:=Pos('=',s); if j>0 then begin s:=copy(s,1,j-1); end; @@ -1402,60 +1403,60 @@ function BESENEncodeString(Value:TBESENANSISTRING;CharFrom:TBESENCharset;CharTo: function BESENGetCodePage(Value:TBESENANSISTRING):TBESENCharset; begin - Value:=BESENANSIUpperCase(Value); - if BESENANSIPos('ISO-8859-10',Value)>0 then begin + Value:=UpperCase(Value); + if Pos('ISO-8859-10',Value)>0 then begin result:=ISO_8859_10; - end else if BESENANSIPos('ISO-8859-1',Value)>0 then begin + end else if Pos('ISO-8859-1',Value)>0 then begin result:=ISO_8859_1; - end else if BESENANSIPos('ISO-8859-2',Value)>0 then begin + end else if Pos('ISO-8859-2',Value)>0 then begin result:=ISO_8859_2; - end else if BESENANSIPos('ISO-8859-3',Value)>0 then begin + end else if Pos('ISO-8859-3',Value)>0 then begin result:=ISO_8859_3; - end else if BESENANSIPos('ISO-8859-4',Value)>0 then begin + end else if Pos('ISO-8859-4',Value)>0 then begin result:=ISO_8859_4; - end else if BESENANSIPos('ISO-8859-5',Value)>0 then begin + end else if Pos('ISO-8859-5',Value)>0 then begin result:=ISO_8859_5; - end else if BESENANSIPos('ISO-8859-6',Value)>0 then begin + end else if Pos('ISO-8859-6',Value)>0 then begin result:=ISO_8859_6; - end else if BESENANSIPos('ISO-8859-7',Value)>0 then begin + end else if Pos('ISO-8859-7',Value)>0 then begin result:=ISO_8859_7; - end else if BESENANSIPos('ISO-8859-8',Value)>0 then begin + end else if Pos('ISO-8859-8',Value)>0 then begin result:=ISO_8859_8; - end else if BESENANSIPos('ISO-8859-9',Value)>0 then begin + end else if Pos('ISO-8859-9',Value)>0 then begin result:=ISO_8859_9; - end else if (BESENANSIPos('WINDOWS-1250',Value)>0) or (BESENANSIPos('X-CP1250',Value)>0) then begin + end else if (Pos('WINDOWS-1250',Value)>0) or (Pos('X-CP1250',Value)>0) then begin result:=CP1250; - end else if (BESENANSIPos('WINDOWS-1251',Value)>0) or (BESENANSIPos('X-CP1251',Value)>0) then begin + end else if (Pos('WINDOWS-1251',Value)>0) or (Pos('X-CP1251',Value)>0) then begin result:=CP1251; - end else if (BESENANSIPos('WINDOWS-1252',Value)>0) or (BESENANSIPos('X-CP1252',Value)>0) then begin + end else if (Pos('WINDOWS-1252',Value)>0) or (Pos('X-CP1252',Value)>0) then begin result:=CP1252; - end else if (BESENANSIPos('WINDOWS-1253',Value)>0) or (BESENANSIPos('X-CP1253',Value)>0) then begin + end else if (Pos('WINDOWS-1253',Value)>0) or (Pos('X-CP1253',Value)>0) then begin result:=CP1253; - end else if (BESENANSIPos('WINDOWS-1254',Value)>0) or (BESENANSIPos('X-CP1254',Value)>0) then begin + end else if (Pos('WINDOWS-1254',Value)>0) or (Pos('X-CP1254',Value)>0) then begin result:=CP1254; - end else if (BESENANSIPos('WINDOWS-1255',Value)>0) or (BESENANSIPos('X-CP1255',Value)>0) then begin + end else if (Pos('WINDOWS-1255',Value)>0) or (Pos('X-CP1255',Value)>0) then begin result:=CP1255; - end else if (BESENANSIPos('WINDOWS-1256',Value)>0) or (BESENANSIPos('X-CP1256',Value)>0) then begin + end else if (Pos('WINDOWS-1256',Value)>0) or (Pos('X-CP1256',Value)>0) then begin result:=CP1256; - end else if (BESENANSIPos('WINDOWS-1257',Value)>0) or (BESENANSIPos('X-CP1257',Value)>0) then begin + end else if (Pos('WINDOWS-1257',Value)>0) or (Pos('X-CP1257',Value)>0) then begin result:=CP1257; - end else if (BESENANSIPos('WINDOWS-1258',Value)>0) or (BESENANSIPos('X-CP1258',Value)>0) then begin + end else if (Pos('WINDOWS-1258',Value)>0) or (Pos('X-CP1258',Value)>0) then begin result:=CP1258; - end else if BESENANSIPos('KOI8-R',Value)>0 then begin + end else if Pos('KOI8-R',Value)>0 then begin result:=KOI8_R; - end else if BESENANSIPos('UTF-7',Value)>0 then begin + end else if Pos('UTF-7',Value)>0 then begin result:=UTF_7; - end else if BESENANSIPos('UTF-8',Value)>0 then begin + end else if Pos('UTF-8',Value)>0 then begin result:=UTF_8; - end else if BESENANSIPos('UTF-16',Value)>0 then begin + end else if Pos('UTF-16',Value)>0 then begin result:=UTF_16; - end else if BESENANSIPos('UTF-32',Value)>0 then begin + end else if Pos('UTF-32',Value)>0 then begin result:=UTF_32; - end else if BESENANSIPos('UCS-4',Value)>0 then begin + end else if Pos('UCS-4',Value)>0 then begin result:=UCS_4; - end else if BESENANSIPos('UCS-2',Value)>0 then begin + end else if Pos('UCS-2',Value)>0 then begin result:=UCS_2; - end else if BESENANSIPos('UNICODE',Value)>0 then begin + end else if Pos('UNICODE',Value)>0 then begin result:=UCS_2; end else begin result:=ISO_8859_1; @@ -1546,11 +1547,11 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; cs:TBESENCharset; begin result:=''; - us:=BESENANSIUpperCase(s); - p1:=BESENANSIPos('=?ISO',us); + us:=UpperCase(s); + p1:=Pos('=?ISO',us); while p1>0 do begin q:=copy(s,p1+2,length(s)); - p2:=BESENANSIPosChar('?',q); + p2:=Pos('?',q); if (p2=0) or (p2>=length(q)-2) or (q[p2+2]<>'?') then begin break; end; @@ -1558,7 +1559,7 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; cs:=BESENGetCodePage(e); encode:=TBESENCHAR(upcase(TBESENCHAR(q[p2+1]))); q:=copy(q,p2+3,length(q)); - p3:=BESENANSIPos('?=',q); + p3:=Pos('?=',q); if p3=0 then begin break; end; @@ -1575,18 +1576,18 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; inc(p1,2+p2+2+p3); delete(s,1,p1); delete(us,1,p1); - p1:=BESENANSIPos('=?ISO',us); + p1:=Pos('=?ISO',us); end; - p1:=BESENANSIPos('=?UTF-7',us); + p1:=Pos('=?UTF-7',us); while p1>0 do begin q:=copy(s,p1+2,length(s)); - p2:=BESENANSIPosChar('?',q); + p2:=Pos('?',q); if (p2=0) or (p2>=length(q)-2) or (q[p2+2]<>'?') then begin break; end; encode:=TBESENCHAR(upcase(TBESENCHAR(q[p2+1]))); q:=copy(q,p2+3,length(q)); - p3:=BESENANSIPos('?=',q); + p3:=Pos('?=',q); if p3=0 then begin break; end; @@ -1603,18 +1604,18 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; inc(p1,2+p2+2+p3); delete(s,1,p1); delete(us,1,p1); - p1:=BESENANSIPos('=?UTF-7',us); + p1:=Pos('=?UTF-7',us); end; - p1:=BESENANSIPos('=?UTF-8',us); + p1:=Pos('=?UTF-8',us); while p1>0 do begin q:=copy(s,p1+2,length(s)); - p2:=BESENANSIPosChar('?',q); + p2:=Pos('?',q); if (p2=0) or (p2>=length(q)-2) or (q[p2+2]<>'?') then begin break; end; encode:=TBESENCHAR(upcase(TBESENCHAR(q[p2+1]))); q:=copy(q,p2+3,length(q)); - p3:=BESENANSIPos('?=',q); + p3:=Pos('?=',q); if p3=0 then begin break; end; @@ -1630,12 +1631,12 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; inc(p1,2+p2+2+p3); delete(s,1,p1); delete(us,1,p1); - p1:=BESENANSIPos('=?UTF-8',us); + p1:=Pos('=?UTF-8',us); end; - p1:=BESENANSIPos('=?',us); + p1:=Pos('=?',us); while p1>0 do begin q:=copy(s,p1+2,length(s)); - p2:=BESENANSIPosChar('?',q); + p2:=Pos('?',q); if (p2=0) or (p2>=length(q)-2) or (q[p2+2]<>'?') then begin break; end; @@ -1645,12 +1646,12 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; result:=result+'=?'; delete(s,1,p1); delete(us,1,p1); - p1:=BESENANSIPos('=?',us); + p1:=Pos('=?',us); continue; end; encode:=TBESENCHAR(upcase(TBESENCHAR(q[p2+1]))); q:=copy(q,p2+3,length(q)); - p3:=BESENANSIPos('?=',q); + p3:=Pos('?=',q); if p3=0 then begin break; end; @@ -1667,7 +1668,7 @@ function BESENISOToUTF8(s:TBESENANSISTRING):TBESENANSISTRING; inc(p1,2+p2+2+p3); delete(s,1,p1); delete(us,1,p1); - p1:=BESENANSIPos('=?',us); + p1:=Pos('=?',us); end; result:=result+BESENEncodeString(s,ISO_8859_1,UTF_8); end; From 5da3d76f1f4cffcf65de539e0ae99634de204467 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 08:35:11 +0200 Subject: [PATCH 12/13] Add files via upload --- src/BESENDeclarativeEnvironmentRecord.pas | 6 +++++- src/BESENHashMap.pas | 4 ++-- src/BESENObject.pas | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/BESENDeclarativeEnvironmentRecord.pas b/src/BESENDeclarativeEnvironmentRecord.pas index 4526215..b57d225 100644 --- a/src/BESENDeclarativeEnvironmentRecord.pas +++ b/src/BESENDeclarativeEnvironmentRecord.pas @@ -108,7 +108,9 @@ constructor TBESENDeclarativeEnvironmentRecord.Create(AInstance:TObject); FillChar(HashBuckets,sizeof(TBESENDeclarativeEnvironmentRecordHashBuckets),#0); First:=nil; Last:=nil; + HashSize:=256; + HashSizeMask:=HashSize-1; HashedItems:=0; HashBucketsUsed:=0; @@ -155,7 +157,9 @@ procedure TBESENDeclarativeEnvironmentRecord.Clear; First:=nil; Last:=nil; LastUsedItem:=nil; + HashSize:=256; + HashSizeMask:=HashSize-1; HashedItems:=0; HashBucketsUsed:=0; @@ -245,7 +249,7 @@ function TBESENDeclarativeEnvironmentRecord.GetKey(const Key:TBESENString;Hash:T if Hash=0 then begin Hash:=BESENHashKey(Key); end; -Hash:=Hash and HashSizeMask; + Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; while assigned(result) and (result^.Key<>Key) do begin result:=result^.HashNext; diff --git a/src/BESENHashMap.pas b/src/BESENHashMap.pas index 3063d94..0c73d19 100644 --- a/src/BESENHashMap.pas +++ b/src/BESENHashMap.pas @@ -177,7 +177,7 @@ procedure TBESENHashMap.GrowAndRehashIfNeeded; function TBESENHashMap.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENHashMapItem; begin - {$ifdef THRhash} + {$ifdef THRhash2} if assigned(LastUsedItem) and (LastUsedItem^.Hash=Hash) then begin {$else} if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin @@ -192,7 +192,7 @@ function TBESENHashMap.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENHa Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; - {$ifdef THRhash} + {$ifdef THRhash2} while assigned(result) and (result^.Hash<>Hash) do begin result:=result^.HashNext; end; diff --git a/src/BESENObject.pas b/src/BESENObject.pas index 51460af..141ebe5 100644 --- a/src/BESENObject.pas +++ b/src/BESENObject.pas @@ -496,7 +496,9 @@ constructor TBESENObjectPropertyContainer.Create(AInstance:TObject;ASorted:boole Last:=nil; EnumeratorFirst:=nil; EnumeratorLast:=nil; + HashSize:=256; + HashSizeMask:=HashSize-1; HashedItems:=0; HashBucketsUsed:=0; @@ -544,7 +546,9 @@ procedure TBESENObjectPropertyContainer.Clear; end; First:=nil; Last:=nil; + HashSize:=256; + HashSizeMask:=HashSize-1; HashedItems:=0; HashBucketsUsed:=0; From 09ae28c1edc30cdb4f51c9d835bdc79eeeaead89 Mon Sep 17 00:00:00 2001 From: tigrazone Date: Tue, 31 Oct 2017 08:39:27 +0200 Subject: [PATCH 13/13] Add files via upload --- src/BESENHashMap.pas | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/BESENHashMap.pas b/src/BESENHashMap.pas index 0c73d19..3d6a1d3 100644 --- a/src/BESENHashMap.pas +++ b/src/BESENHashMap.pas @@ -177,11 +177,7 @@ procedure TBESENHashMap.GrowAndRehashIfNeeded; function TBESENHashMap.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENHashMapItem; begin - {$ifdef THRhash2} - if assigned(LastUsedItem) and (LastUsedItem^.Hash=Hash) then begin - {$else} if assigned(LastUsedItem) and (LastUsedItem^.Key=Key) then begin - {$endif} result:=LastUsedItem; Hash:=result^.Hash; @@ -192,15 +188,9 @@ function TBESENHashMap.GetKey(const Key:TBESENString;Hash:TBESENHash=0):PBESENHa Hash:=Hash and HashSizeMask; result:=HashBuckets[Hash].HashFirst; - {$ifdef THRhash2} - while assigned(result) and (result^.Hash<>Hash) do begin - result:=result^.HashNext; - end; - {$else} while assigned(result) and (result^.Key<>Key) do begin result:=result^.HashNext; end; - {$endif} end;