LCL: ReadPoText: small optimization

git-svn-id: trunk@34217 -
This commit is contained in:
mattias 2011-12-16 01:07:11 +00:00
parent 4b8a579110
commit 93a466e9bb

View File

@ -110,6 +110,7 @@ type
FModuleList: TStringList; FModuleList: TStringList;
procedure RemoveTaggedItems(aTag: Integer); procedure RemoveTaggedItems(aTag: Integer);
procedure RemoveUntaggedModules; procedure RemoveUntaggedModules;
function IsKey(Txt, Key: PChar): boolean;
public public
constructor Create; constructor Create;
constructor Create(const AFilename: String; Full:boolean=false); constructor Create(const AFilename: String; Full:boolean=false);
@ -489,6 +490,18 @@ begin
end; end;
end; end;
function TPOFile.IsKey(Txt, Key: PChar): boolean;
begin
if Txt=nil then exit(false);
if Key=nil then exit(true);
repeat
if Key^=#0 then exit(true);
if Txt^<>Key^ then exit(false);
inc(Key);
inc(Txt);
until false;
end;
constructor TPOFile.Create; constructor TPOFile.Create;
begin begin
inherited Create; inherited Create;
@ -646,7 +659,7 @@ var
function TestPrefixStr(AIndex: Integer): boolean; function TestPrefixStr(AIndex: Integer): boolean;
var var
s: string; s: PChar;
l: Integer; l: Integer;
begin begin
case aIndex of case aIndex of
@ -654,11 +667,11 @@ var
ciMsgStr: s:=sMsgStr; ciMsgStr: s:=sMsgStr;
ciPrevMsgId: s:=sPrevMsgId; ciPrevMsgId: s:=sPrevMsgId;
end; end;
L := Length(s); result := IsKey(LineStart, s);
result := CompareMem(LineStart, pchar(s), L);
if Result then begin if Result then begin
StoreCollectedLine; StoreCollectedLine;
CollectedIndex := AIndex; CollectedIndex := AIndex;
L := Length(s);
Line:=UTF8CStringToUTF8String(LineStart+L,LineLen-L-1); Line:=UTF8CStringToUTF8String(LineStart+L,LineLen-L-1);
end; end;
end; end;
@ -682,7 +695,7 @@ begin
while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd); while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd);
LineLen:=LineEnd-LineStart; LineLen:=LineEnd-LineStart;
if LineLen>0 then begin if LineLen>0 then begin
if CompareMem(LineStart,sCommentIdentifier,3) then begin if IsKey(LineStart,sCommentIdentifier) then begin
AddEntry; AddEntry;
Identifier:=copy(s,LineStart-p+4,LineLen-3); Identifier:=copy(s,LineStart-p+4,LineLen-3);
// the RTL creates identifier paths with point instead of colons // the RTL creates identifier paths with point instead of colons
@ -693,12 +706,12 @@ begin
end else if TestPrefixStr(ciMsgId) then begin end else if TestPrefixStr(ciMsgId) then begin
end else if TestPrefixStr(ciMsgStr) then begin end else if TestPrefixStr(ciMsgStr) then begin
end else if TestPrefixStr(ciPrevMsgId) then begin end else if TestPrefixStr(ciPrevMsgId) then begin
end else if CompareMem(LineStart, sMsgCtxt,9) then begin end else if IsKey(LineStart, sMsgCtxt) then begin
Context:= Copy(LineStart, 10, LineLen-10); Context:= Copy(LineStart, 10, LineLen-10);
end else if CompareMem(LineStart, sFlags, 3) then begin end else if IsKey(LineStart, sFlags) then begin
Flags := copy(LineStart, 4, LineLen-3); Flags := copy(LineStart, 4, LineLen-3);
end else if (LineStart^='"') then begin end else if (LineStart^='"') then begin
if (MsgID='') and CompareMem(LineStart,sCharSetIdentifier,35) then if (MsgID='') and IsKey(LineStart,sCharSetIdentifier) then
begin begin
FCharSet:=copy(LineStart,36,LineLen-38); FCharSet:=copy(LineStart,36,LineLen-38);
if SysUtils.CompareText(FCharSet,'UTF-8')<>0 then begin if SysUtils.CompareText(FCharSet,'UTF-8')<>0 then begin
@ -718,7 +731,7 @@ begin
end; end;
end; end;
Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2); Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2);
end else if CompareMem(LineStart, sPrevStr, 4) then begin end else if IsKey(LineStart, sPrevStr) then begin
Line := Line + UTF8CStringToUTF8String(LineStart+5,LineLen-6); Line := Line + UTF8CStringToUTF8String(LineStart+5,LineLen-6);
end else if LineStart^='#' then begin end else if LineStart^='#' then begin
if Comments<>'' then if Comments<>'' then