Skip to content

Commit bd3f0c7

Browse files
authored
Merge pull request #155 from georges-hatem/main
micro-optimizations
2 parents fe9569b + 4e5e481 commit bd3f0c7

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

entries/ghatem-fpc/src/OneBRC-dirty.lpr

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ procedure TBRCDictionary.InternalFind(const aKey: Cardinal; out aFound: Boolean;
205205
// found match
206206
aIndex := vIdx;
207207
aFound := True;
208-
break;
208+
exit;
209209
end;
210210
if FHashes[vIdx] = 0 then begin
211211
// found empty bucket to use
212212
aIndex := vIdx;
213213
aFound := False;
214-
break;
214+
exit;
215215
end;
216216
end;
217217
end;
@@ -263,12 +263,8 @@ function RoundExInteger (const aTemp: Double): Integer; inline;
263263
{ TOneBRC }
264264

265265
function Compare(AList: TStringList; AIndex1, AIndex2: Integer): Integer;
266-
var
267-
Str1, Str2: String;
268266
begin
269-
Str1 := AList.Strings[AIndex1];
270-
Str2 := AList.Strings[AIndex2];
271-
Result := CompareStr(Str1, Str2);
267+
Result := CompareStr(AList.Strings[AIndex1], AList.Strings[AIndex2]);
272268
end;
273269

274270
procedure TOneBRC.ExtractLineData(const aStart: Int64; const aEnd: Int64; out aLength: ShortInt; out aTemp: SmallInt);
@@ -285,8 +281,7 @@ procedure TOneBRC.ExtractLineData(const aStart: Int64; const aEnd: Int64; out aL
285281

286282
if FData[J] <> ';' then begin
287283
Dec (J);
288-
if FData[J] <> ';' then
289-
Dec(J);
284+
Dec (J, Ord (FData[J] <> ';'));
290285
end;
291286
// I is the position of the semi-colon, extract what's before and after it
292287

@@ -386,9 +381,8 @@ procedure TOneBRC.ProcessData (aThreadNb: TThreadCount; aStartIdx: Int64; aEndId
386381
vFound: Boolean;
387382
begin
388383
for I := 0 to cNumStations - 1 do begin
389-
vData := @FDictionary.FThreadData[aThreadNb][I];
390-
vData^.Max := -2000;
391-
vData^.Min := 2000;
384+
FDictionary.FThreadData[aThreadNb][I].Max := -2000;
385+
FDictionary.FThreadData[aThreadNb][I].Min := 2000;
392386
end;
393387

394388
i := aStartIdx;
@@ -527,7 +521,6 @@ procedure TOneBRC.GenerateOutput;
527521
vStations.Add(iStationName);
528522
end;
529523
vStations.EndUpdate;
530-
//vStations.AddStrings(FDictionary.FStationNames);
531524
vStations.CustomSort (@Compare);
532525

533526
I := 0;

0 commit comments

Comments
 (0)