Changeset 2


Ignore:
Timestamp:
Aug 18, 2017, 10:28:14 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Much faster parsing of lshistory output using state machine.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      lib
      CC2SVN.lps
      CC2SVN.exe
      CC2SVN.res
  • trunk/CC2SVN.lpi

    r1 r2  
    22<CONFIG>
    33  <ProjectOptions>
    4     <Version Value="9"/>
     4    <Version Value="10"/>
    55    <PathDelim Value="\"/>
    66    <General>
  • trunk/Packages/Common

    • Property svn:ignore set to
      lib
  • trunk/Packages/TemplateGenerics

    • Property svn:ignore set to
      lib
  • trunk/UFormMain.lfm

    r1 r2  
    1111  OnDestroy = FormDestroy
    1212  OnShow = FormShow
    13   LCLVersion = '1.6.0.4'
     13  LCLVersion = '1.6.4.0'
    1414  WindowState = wsMaximized
    1515  object ListView1: TListView
     
    8989    object EditDir: TEdit
    9090      Left = 136
    91       Height = 28
     91      Height = 23
    9292      Top = 8
    9393      Width = 600
     
    107107    object Label1: TLabel
    108108      Left = 8
    109       Height = 20
     109      Height = 15
    110110      Top = 13
    111       Width = 90
     111      Width = 72
    112112      Caption = 'ClearCase dir:'
    113113      ParentColor = False
  • trunk/UFormMain.pas

    r1 r2  
    207207
    208208procedure TFormMain.JobLoad(Job: TJob);
     209type
     210  TParseState = (psTime, psHumanName, psUserName, psOperation, psLocation,
     211    psElementType, psCommand, psComment, psNewLine);
    209212var
    210213  Lines: TStringList;
    211214  HistoryItem: THistoryItem;
    212215  Content: string;
     216  State: TParseState;
     217  Text: string;
     218  StartIndex: Integer;
     219  I: Integer;
    213220begin
    214221  Lines := TStringList.Create;
     
    219226  Lines.LoadFromFile('log.txt');
    220227{$ENDIF}
    221   Job.Progress.Max := Lines.Count;
    222228  Content := Lines.Text;
    223   while Length(Content) > 0 do begin
    224     HistoryItem := THistoryItem.Create;
    225     HistoryItem.Time := XMLTimeToDateTime(ParseLine(Content, '|'));
    226     HistoryItem.HumanName := ParseLine(Content, '|');
    227     HistoryItem.UserName := ParseLine(Content, '|');
    228     HistoryItem.Operation := ParseLine(Content, '|');
    229     HistoryItem.Location := ParseLine(Content, '|');
    230     HistoryItem.ElementType := ParseLine(Content, '|');
    231     HistoryItem.Command := ParseLine(Content, '|');
    232     HistoryItem.LabelName := ParseLine(Content, '|');
    233     HistoryItem.Comment := ParseLine(Content, '|');
    234     if Copy(Content, 1, 2) = #13#10 then Delete(Content, 1, 2);
    235     History.Add(HistoryItem);
     229  Job.Progress.Max := Length(Content);
     230  StartIndex := 1;
     231  State := psTime;
     232  I := 1;
     233  while I < Length(Content) do begin
     234    if Content[I] = '|' then begin
     235      Text := Copy(Content, StartIndex, I - StartIndex);
     236      StartIndex := I + 1;
     237      if State = psTime then begin
     238        HistoryItem := THistoryItem.Create;
     239        HistoryItem.Time := XMLTimeToDateTime(Text);
     240        State := psHumanName;
     241      end else
     242      if State = psHumanName then begin
     243        HistoryItem.HumanName := Text;
     244        State := psUserName;
     245      end else
     246      if State = psUserName then begin
     247        HistoryItem.UserName := Text;
     248        State := psOperation;
     249      end else
     250      if State = psOperation then begin
     251        HistoryItem.Operation := Text;
     252        State := psLocation;
     253      end else
     254      if State = psLocation then begin
     255        HistoryItem.Location := Text;
     256        State := psElementType;
     257      end else
     258      if State = psElementType then begin
     259        HistoryItem.ElementType := Text;
     260        State := psCommand;
     261      end else
     262      if State = psCommand then begin
     263        HistoryItem.Command := Text;
     264        State := psComment;
     265      end else
     266      if State = psComment then begin
     267        HistoryItem.Comment := Text;
     268        History.Add(HistoryItem);
     269        State := psNewLine;
     270      end;
     271    end else
     272    if State = psNewLine then begin
     273      if Content[I] = #10 then begin
     274        State := psTime;
     275        StartIndex := I + 1;
     276      end;
     277    end;
     278    Inc(I);
     279
     280    Job.Progress.Value := I;
    236281    if Job.Terminate then Break;
    237282  end;
Note: See TracChangeset for help on using the changeset viewer.