Browse Source

merge r17587 from cpstrnew branch by inoussa:
fpc_AnsiStr_To_AnsiStr : avoid code page conversion when possible.

git-svn-id: trunk@19120 -

paul 14 years ago
parent
commit
7c21524892
1 changed files with 17 additions and 3 deletions
  1. 17 3
      rtl/inc/astrings.inc

+ 17 - 3
rtl/inc/astrings.inc

@@ -416,11 +416,25 @@ Var
   Size : SizeInt;
   temp : UnicodeString;
 begin
-  temp:=S;
   result:='';
-  Size:=Length(temp);
+  Size:=Length(S);
   if Size>0 then
-    widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Pointer(temp)),result,cp,Size);
+    begin
+      if (cp=0) then
+        cp:=DefaultSystemCodePage;
+      if (StringCodePage(S)=cp) then
+        begin
+          SetLength(result,Size);
+          Move(S[1],result[1],Size);
+          PAnsiRec(Pointer(S)-AnsiFirstOff)^.CodePage:=cp;
+        end
+      else
+        begin
+          temp:=S;
+          Size:=Length(temp);
+          widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Pointer(temp)),result,cp,Size);
+        end;
+    end;
 end;
 
 Function fpc_AnsiStr_To_AnsiStr (const S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): RawByteString; [external name 'FPC_ANSISTR_TO_ANSISTR'];