Skip to content

Commit b8135d5

Browse files
committed
unification of results in between lazarus and delphi, adjustment for 32-bit
1 parent f81f49c commit b8135d5

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

generator/Common/generate.common.pas

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ TGenerator = class(TObject)
2424
FStationNames: TStringList;
2525

2626
procedure BuildStationNames;
27-
function GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize: Int64;
28-
ATimeElapsed: TDateTime): String;
27+
function GenerateProgressBar(APBPosition, APBMax, APBWIdth: Integer;
28+
AFileSize: Int64; ATimeElapsed: TDateTime): String;
2929
function Rng1brc(Range: longint): longint;
3030
protected
3131
public
@@ -37,7 +37,7 @@ TGenerator = class(TObject)
3737
end;
3838

3939
{$IFNDEF FPC}
40-
TStringArray = array of string;
40+
TStringArray = array of Utf8String;
4141
TWriteBufStream = TFileStream;
4242
{$ENDIF}
4343

@@ -48,7 +48,8 @@ implementation
4848
{$IFDEF FPC}
4949
, streamex
5050
{$ELSE}
51-
, System.Diagnostics
51+
, System.Diagnostics
52+
{$IF defined(MSWINDOWS)}, Winapi.Windows{$ENDIF}
5253
{$ENDIF}
5354
;
5455

@@ -113,7 +114,7 @@ procedure TGenerator.BuildStationNames;
113114
end;
114115
stop := GetTickCount64;
115116
{$ELSE}
116-
start := TStopwatch.GetTimeStamp;
117+
start := {$IF defined(MSWINDOWS)}GetTickCount64{$ELSE}TStopwatch.GetTimeStamp{$ENDIF};
117118
while not streamReader.EndOfStream do
118119
begin
119120
entry := streamReader.ReadLine;
@@ -124,7 +125,7 @@ procedure TGenerator.BuildStationNames;
124125
Inc(count);
125126
end;
126127
end;
127-
stop := TStopwatch.GetTimeStamp;
128+
stop := {$IF defined(MSWINDOWS)}GetTickCount64{$ELSE}TStopwatch.GetTimeStamp{$ENDIF};
128129
{$ENDIF}
129130
finally
130131
streamReader.Free;
@@ -143,14 +144,13 @@ procedure TGenerator.BuildStationNames;
143144
WriteLn;
144145
end;
145146

146-
function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth, AFileSize: Int64;
147-
ATimeElapsed: TDateTime): String;
147+
function TGenerator.GenerateProgressBar(APBPosition, APBMax, APBWIdth: Integer; AFileSize: Int64; ATimeElapsed: TDateTime): String;
148148
var
149149
percentDone: Double;
150150
filled: Integer;
151151
begin
152-
percentDone := (100 * APBPosition) / APBMax;
153-
filled := (APBWIdth * APBPosition) div APBMax;
152+
percentDone := 100 * (APBPosition / APBMax);
153+
filled := trunc(APBWIdth * (percentDone / 100));
154154
Result := '[';
155155
Result := Result + StringOfChar('#', filled);
156156
Result := Result + StringOfChar('-', APBWIdth - filled);
@@ -178,12 +178,11 @@ function TGenerator.Rng1brc(Range: Integer): Integer;
178178

179179
procedure TGenerator.Generate;
180180
var
181-
index, progressCount, progressBatch: Int64;
182-
stationId: Int64;
183-
randomTemp: Integer;
181+
index, progressCount, progressBatch: Integer;
182+
stationId, randomTemp: Integer;
184183
randomTempStr: String[4];
185184
outputFileStream: TFileStream;
186-
chunkLine, randomTempFinal: String;
185+
chunkLine, randomTempFinal: Utf8String;
187186
stationArray, temperatureArray: TStringArray;
188187
LenStationArray, LenTemperatureArray: Array of Integer;
189188
chunkCount, chunkLen, stationsCount, temperaturesCount: Integer;

generator/Common/generate.console.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface
4444
var
4545
inputFilename: String = '';
4646
outputFilename: String = '';
47-
lineCount: Int64 = 0;
47+
lineCount: Integer = 0;
4848

4949
procedure WriteHelp;
5050

generator/Delphi/src/generator.dpr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ uses
88
generate.common in '..\..\Common\generate.common.pas',
99
generate.console in '..\..\Common\generate.console.pas';
1010

11-
{$I version.inc}
11+
{$I '..\..\Common\version.inc'}
1212

1313
type
1414

@@ -193,7 +193,7 @@ begin
193193
begin
194194
tmpLineCount := FParams.ValueFromIndex[J].Replace('_', '', [rfReplaceAll]);
195195

196-
if not TryStrToInt64(tmpLineCount, lineCount) then
196+
if not TryStrToInt(tmpLineCount, lineCount) then
197197
begin
198198
WriteLn(Format(rsInvalidInteger, [tmpLineCount]));
199199
inc(invalid);

generator/Lazarus/src/generator.lpr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ procedure TOneBRCGenerator.DoRun;
111111
cLongOptNumber
112112
);
113113
tmpLineCount:= StringReplace(tmpLineCount, '_', '', [rfReplaceAll]);
114-
if not TryStrToInt64(tmpLineCount, lineCount) then
114+
if not TryStrToInt(tmpLineCount, lineCount) then
115115
begin
116116
WriteLn(Format(rsInvalidInteger, [ tmpLineCount ]));
117117
Terminate;

0 commit comments

Comments
 (0)