فهرست منبع

* prevent going through (the expensive) InternalSetCodePage when changing
the code page of a string with refcount=1 and without conversion (happens
a lot in internal RTL routines)

git-svn-id: trunk@24985 -

Jonas Maebe 12 سال پیش
والد
کامیت
345ca6f187
1فایلهای تغییر یافته به همراه6 افزوده شده و 2 حذف شده
  1. 6 2
      rtl/inc/astrings.inc

+ 6 - 2
rtl/inc/astrings.inc

@@ -1409,8 +1409,12 @@ procedure InternalSetCodePage(var s : RawByteString; CodePage : TSystemCodePage;
   extra exception frames }
   extra exception frames }
 procedure SetCodePage(var s : RawByteString; CodePage : TSystemCodePage; Convert : Boolean = True);
 procedure SetCodePage(var s : RawByteString; CodePage : TSystemCodePage; Convert : Boolean = True);
   begin
   begin
-    if (S<>'') and (StringCodePage(S)<>CodePage) then
-      InternalSetCodePage(s,CodePage,Convert);
+    if (S='') or (PAnsiRec(pointer(S)-AnsiFirstOff)^.CodePage=CodePage) then
+      exit
+    else if not Convert and (PAnsiRec(pointer(S)-AnsiFirstOff)^.Ref=1) then
+      PAnsiRec(pointer(S)-AnsiFirstOff)^.CodePage:=CodePage
+    else
+      InternalSetCodePage(S,CodePage,Convert);
   end;
   end;
 {$endif FPC_HAS_ANSISTR_SETCODEPAGE}
 {$endif FPC_HAS_ANSISTR_SETCODEPAGE}