From 0cd9e7fee9c46612149c712c80d5ef9e44d57527 Mon Sep 17 00:00:00 2001 From: sergei Date: Thu, 23 Feb 2012 21:36:31 +0000 Subject: [PATCH] + procedure BufAppendString(TWideCharBuf,XMLString) for convenience - removed {$ifdef fpc}, CompareMem is no longer slower than CompareWord, so it can be used always. git-svn-id: trunk@20417 - --- packages/fcl-xml/src/xmlutils.pp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/fcl-xml/src/xmlutils.pp b/packages/fcl-xml/src/xmlutils.pp index b2dc71925d..2e1c2c6ece 100644 --- a/packages/fcl-xml/src/xmlutils.pp +++ b/packages/fcl-xml/src/xmlutils.pp @@ -216,6 +216,7 @@ type procedure BufAllocate(var ABuffer: TWideCharBuf; ALength: Integer); procedure BufAppend(var ABuffer: TWideCharBuf; wc: WideChar); procedure BufAppendChunk(var ABuf: TWideCharBuf; pstart, pend: PWideChar); +procedure BufAppendString(var ABuf: TWideCharBuf; const AValue: XMLString); function BufEquals(const ABuf: TWideCharBuf; const Arg: XMLString): Boolean; procedure BufNormalize(var Buf: TWideCharBuf; out Modified: Boolean); @@ -490,11 +491,7 @@ end; function KeyCompare(const Key1: XMLString; Key2: Pointer; Key2Len: Integer): Boolean; begin -{$IFDEF FPC} - Result := (Length(Key1)=Key2Len) and (CompareWord(Pointer(Key1)^, Key2^, Key2Len) = 0); -{$ELSE} Result := (Length(Key1)=Key2Len) and CompareMem(Pointer(Key1), Key2, Key2Len*2); -{$ENDIF} end; { THashTable } @@ -972,6 +969,22 @@ begin Inc(ABuf.Length, Len); end; +procedure BufAppendString(var ABuf: TWideCharBuf; const AValue: XMLString); +var + Len: Integer; +begin + Len := Length(AValue); + if Len <= 0 then + Exit; + if Len >= ABuf.MaxLength - ABuf.Length then + begin + ABuf.MaxLength := (Len + ABuf.Length)*2; + ReallocMem(ABuf.Buffer, ABuf.MaxLength * sizeof(WideChar)); + end; + Move(PWideChar(AValue)^, ABuf.Buffer[ABuf.Length], Len * sizeof(WideChar)); + Inc(ABuf.Length, Len); +end; + function BufEquals(const ABuf: TWideCharBuf; const Arg: XMLString): Boolean; begin Result := (ABuf.Length = Length(Arg)) and