Browse Source

+ 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 -

sergei 13 years ago
parent
commit
0cd9e7fee9
1 changed files with 17 additions and 4 deletions
  1. 17 4
      packages/fcl-xml/src/xmlutils.pp

+ 17 - 4
packages/fcl-xml/src/xmlutils.pp

@@ -216,6 +216,7 @@ type
 procedure BufAllocate(var ABuffer: TWideCharBuf; ALength: Integer);
 procedure BufAllocate(var ABuffer: TWideCharBuf; ALength: Integer);
 procedure BufAppend(var ABuffer: TWideCharBuf; wc: WideChar);
 procedure BufAppend(var ABuffer: TWideCharBuf; wc: WideChar);
 procedure BufAppendChunk(var ABuf: TWideCharBuf; pstart, pend: PWideChar);
 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;
 function BufEquals(const ABuf: TWideCharBuf; const Arg: XMLString): Boolean;
 procedure BufNormalize(var Buf: TWideCharBuf; out Modified: Boolean);
 procedure BufNormalize(var Buf: TWideCharBuf; out Modified: Boolean);
 
 
@@ -490,11 +491,7 @@ end;
 
 
 function KeyCompare(const Key1: XMLString; Key2: Pointer; Key2Len: Integer): Boolean;
 function KeyCompare(const Key1: XMLString; Key2: Pointer; Key2Len: Integer): Boolean;
 begin
 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);
   Result := (Length(Key1)=Key2Len) and CompareMem(Pointer(Key1), Key2, Key2Len*2);
-{$ENDIF}
 end;
 end;
 
 
 { THashTable }
 { THashTable }
@@ -972,6 +969,22 @@ begin
   Inc(ABuf.Length, Len);
   Inc(ABuf.Length, Len);
 end;
 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;
 function BufEquals(const ABuf: TWideCharBuf; const Arg: XMLString): Boolean;
 begin
 begin
   Result := (ABuf.Length = Length(Arg)) and
   Result := (ABuf.Length = Length(Arg)) and