@@ -82,17 +82,17 @@ TBRCDictionary = class
8282
8383 // searches for a given key, returns if found the key and the storage index
8484 // (or, if not found, which index to use next)
85- procedure InternalFind (const aKey: Cardinal; out aFound: Boolean; out aIndex: THashSize);
85+ procedure InternalFind (const aKey: Cardinal; out aFound: Boolean; out aIndex: THashSize); { $IFNDEF VALGRIND } inline; { $ENDIF }
8686
8787 public
8888 constructor Create;
8989 destructor Destroy; override;
9090
9191 // simple wrapper to find station-record pointers
92- function TryGetValue (const aKey: Cardinal; const aThreadNb: TThreadCount; out aValue: PStationData): Boolean; inline;
92+ function TryGetValue (const aKey: Cardinal; const aThreadNb: TThreadCount; out aValue: PStationData): Boolean;
9393
9494 // multithread-unprotected: adds a firstly-encountered station-data (temp, name)
95- procedure Add (const aHashIdx: THashSize; const aThreadNb: TThreadCount; const aTemp: SmallInt; const aStationName: AnsiString); inline;
95+ procedure Add (const aHashIdx: THashSize; const aThreadNb: TThreadCount; const aTemp: SmallInt; const aStationName: AnsiString); { $IFNDEF VALGRIND } inline; { $ENDIF }
9696
9797 // multithread-protected: safely assign a slot for a given key
9898 function AtomicRegisterHash (const aKey: Cardinal): THashSize;
@@ -114,7 +114,7 @@ TOneBRC = class
114114 FDictionary: TBRCDictionary;
115115
116116 // for a line between idx [aStart; aEnd], returns the station-name length, and the integer-value of temperature
117- procedure ExtractLineData (const aStart: Int64; const aEnd: Int64; out aLength: ShortInt; out aTemp: SmallInt); inline;
117+ procedure ExtractLineData (const aStart: Int64; const aEnd: Int64; out aLength: ShortInt; out aTemp: SmallInt); { $IFNDEF VALGRIND } inline; { $ENDIF }
118118
119119 public
120120 constructor Create (const aThreadCount: TThreadCount);
@@ -564,6 +564,8 @@ procedure TOneBRC.GenerateOutput;
564564 vHash: Cardinal;
565565 vStations: TStringList;
566566 iStationName: AnsiString;
567+ vIdx: THashSize;
568+ vRes: Boolean;
567569begin
568570 vStream := TStringStream.Create;
569571 vStations := TStringList.Create;
@@ -587,7 +589,10 @@ procedure TOneBRC.GenerateOutput;
587589 // would it be more efficient to store the hash as well?
588590 // debatable, and the whole output generation is < 0.3 seconds, so not exactly worth it
589591 vHash := crc32c(0 , @vStations[i][1 ], Length (vStations[i]));
590- FDictionary.TryGetValue(vHash, 0 , vData);
592+
593+ FDictionary.InternalFind (vHash, vRes, vIdx);
594+ vData := @FDictionary.FThreadData[0 ][FDictionary.FIndexes[vIdx]];
595+
591596 vMean := RoundExInteger(vData^.Sum/vData^.Count/10 );
592597
593598 vStream.WriteString(
0 commit comments