Skip to content

Commit 90fb16b

Browse files
committed
fast but dirty attempt, code needs cleanup / comments
1 parent 988a018 commit 90fb16b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const
1414
cNumStations = 42000;
15-
cDictSize = 42000 * 4;
15+
cDictSize = 42000 * 4 + 1;
1616
cThreadCount = 32;
1717

1818
c0ascii: ShortInt = 48;
@@ -285,10 +285,10 @@ procedure TOneBRC.ExtractLineData(const aStart: Int64; const aEnd: Int64; out aL
285285
// can safely skip 3: ^^^
286286
J := aEnd - 3;
287287

288-
while True do begin
289-
if FData[J] = ';' then
290-
break;
291-
Dec(J);
288+
if FData[J] <> ';' then begin
289+
Dec (J);
290+
if FData[J] <> ';' then
291+
Dec(J);
292292
end;
293293
// I is the position of the semi-colon, extract what's before and after it
294294

@@ -313,13 +313,16 @@ procedure TOneBRC.ExtractLineData(const aStart: Int64; const aEnd: Int64; out aL
313313
// aTemp := -aTemp;
314314

315315
vIsNeg := Ord (FData[J+1] <> '-');
316-
aTemp := (Ord(FData[aEnd]) - c0ascii)
317-
+ 10 *(Ord(FData[aEnd-2]) - c0ascii);
318316

319-
if (J+4 - vIsNeg < aEnd) then begin
320-
aTemp := aTemp + 100*(Ord(FData[aEnd-3]) - c0ascii);
321-
end;
322-
aTemp := (vIsNeg * 2 - 1) * aTemp;
317+
aTemp := (
318+
(Ord(FData[aEnd]) - c0ascii)
319+
+ 10 *(Ord(FData[aEnd-2]) - c0ascii)
320+
+ Ord ((J+4 - vIsNeg < aEnd)) * 100*(Ord(FData[aEnd-3]) - c0ascii)
321+
) * (vIsNeg * 2 - 1);
322+
//if (J+4 - vIsNeg < aEnd) then begin
323+
//aTemp := aTemp
324+
//end;
325+
//aTemp := (vIsNeg * 2 - 1) * aTemp;
323326
end;
324327

325328
//---------------------------------------------------

0 commit comments

Comments
 (0)