Browse Source

* remove maxlen field from ansistring/widestrings

peter 21 years ago
parent
commit
b3e3030e6f
7 changed files with 68 additions and 89 deletions
  1. 6 5
      compiler/cresstr.pas
  2. 12 17
      compiler/ncgcon.pas
  3. 6 3
      compiler/ncginl.pas
  4. 9 4
      compiler/ncgmem.pas
  5. 6 11
      compiler/ptconst.pas
  6. 16 27
      rtl/inc/astrings.inc
  7. 13 22
      rtl/inc/wstrings.inc

+ 6 - 5
compiler/cresstr.pas

@@ -155,9 +155,8 @@ procedure TResourceStrings.CreateResourceStringList;
             objectlibrary.getdatalabel(l1);
             resourcestringlist.concat(tai_const.create_sym(l1));
             consts.concat(tai_align.Create(const_align(sizeof(aint))));
-            consts.concat(tai_const.create_32bit(len));
-            consts.concat(tai_const.create_32bit(len));
             consts.concat(tai_const.create_32bit(-1));
+            consts.concat(tai_const.create_32bit(len));
             consts.concat(tai_label.create(l1));
             getmem(s,len+1);
             move(Value^,s^,len);
@@ -173,9 +172,8 @@ procedure TResourceStrings.CreateResourceStringList;
        L:=Length(Name);
        resourcestringlist.concat(tai_const.create_sym(l1));
        consts.concat(tai_align.Create(const_align(sizeof(aint))));
-       consts.concat(tai_const.create_32bit(l));
-       consts.concat(tai_const.create_32bit(l));
        consts.concat(tai_const.create_32bit(-1));
+       consts.concat(tai_const.create_32bit(l));
        consts.concat(tai_label.create(l1));
        getmem(s,l+1);
        move(Name[1],s^,l);
@@ -295,7 +293,10 @@ end;
 end.
 {
   $Log$
-  Revision 1.25  2004-06-20 08:55:29  florian
+  Revision 1.26  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.25  2004/06/20 08:55:29  florian
     * logs truncated
 
   Revision 1.24  2004/06/16 20:07:07  florian

+ 12 - 17
compiler/ncgcon.pas

@@ -343,9 +343,8 @@ implementation
                                        { before the string the following sequence must be found:
                                          <label>
                                            constsymbol <datalabel>
-                                           constint <len>
-                                           constint <len>
                                            constint -1
+                                           constint <len>
                                          we must then return <label> to reuse
                                        }
                                        hp2:=tai(lastlabelhp.previous);
@@ -356,14 +355,11 @@ implementation
                                           (tai(hp2.previous).typ=ait_const_aint) and
                                           (tai_const(hp2.previous).value=len) and
                                           assigned(hp2.previous.previous) and
-                                          (tai(hp2.previous.previous).typ=ait_const_aint) and
-                                          (tai_const(hp2.previous.previous).value=len) and
+                                          (tai(hp2.previous.previous).typ=ait_const_ptr) and
                                           assigned(hp2.previous.previous.previous) and
-                                          (tai(hp2.previous.previous.previous).typ=ait_const_ptr) and
-                                          assigned(hp2.previous.previous.previous.previous) and
-                                          (tai(hp2.previous.previous.previous.previous).typ=ait_label) then
+                                          (tai(hp2.previous.previous.previous).typ=ait_label) then
                                          begin
-                                           lastlabel:=tai_label(hp2.previous.previous.previous.previous).l;
+                                           lastlabel:=tai_label(hp2.previous.previous.previous).l;
                                            same_string:=true;
                                            j:=0;
                                            if len>0 then
@@ -459,9 +455,8 @@ implementation
                                 objectlibrary.getdatalabel(l2);
                                 Consts.concat(Tai_label.Create(l2));
                                 Consts.concat(Tai_const_symbol.Create(l1));
-                                Consts.concat(Tai_const.Create_32bit(len));
-                                Consts.concat(Tai_const.Create_32bit(len));
                                 Consts.concat(Tai_const.Create_32bit(-1));
+                                Consts.concat(Tai_const.Create_32bit(len));
                                 Consts.concat(Tai_label.Create(l1));
                                 getmem(pc,len+2);
                                 move(value_str^,pc^,len);
@@ -485,9 +480,8 @@ implementation
                                 objectlibrary.getdatalabel(l2);
                                 Consts.concat(Tai_label.Create(l2));
                                 Consts.concat(Tai_const.Create_sym(l1));
-                                Consts.concat(Tai_const.Create_aint(len));
-                                Consts.concat(Tai_const.Create_aint(len));
                                 Consts.concat(Tai_const.Create_aint(-1));
+                                Consts.concat(Tai_const.Create_aint(len));
                                 Consts.concat(Tai_label.Create(l1));
                                 getmem(pc,len+2);
                                 move(value_str^,pc^,len);
@@ -511,9 +505,8 @@ implementation
                                 objectlibrary.getdatalabel(l2);
                                 Consts.concat(Tai_label.Create(l2));
                                 Consts.concat(Tai_const_symbol.Create(l1));
-                                Consts.concat(Tai_const.Create_32bit(len));
-                                Consts.concat(Tai_const.Create_32bit(len));
                                 Consts.concat(Tai_const.Create_32bit(-1));
+                                Consts.concat(Tai_const.Create_32bit(len));
                                 Consts.concat(Tai_label.Create(l1));
                                 getmem(pc,len+2);
                                 move(value_str^,pc^,len);
@@ -541,9 +534,8 @@ implementation
                                 { we use always UTF-16 coding for constants }
                                 { at least for now                          }
                                 { Consts.concat(Tai_const.Create_8bit(2)); }
-                                Consts.concat(Tai_const.Create_aint(len));
-                                Consts.concat(Tai_const.Create_aint(len));
                                 Consts.concat(Tai_const.Create_aint(-1));
+                                Consts.concat(Tai_const.Create_aint(len));
                                 Consts.concat(Tai_label.Create(l1));
                                 for i:=0 to len-1 do
                                   Consts.concat(Tai_const.Create_16bit(pcompilerwidestring(value_str)^.data[i]));
@@ -729,7 +721,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.43  2004-06-20 08:55:29  florian
+  Revision 1.44  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.43  2004/06/20 08:55:29  florian
     * logs truncated
 
   Revision 1.42  2004/06/18 15:16:46  peter

+ 6 - 3
compiler/ncginl.pas

@@ -330,11 +330,11 @@ implementation
          end
         else
          begin
-           { length in ansi strings is at offset sizeof(aint)*2 }
+           { length in ansi/wide strings is at offset -sizeof(aint) }
            location_force_reg(exprasmlist,left.location,OS_ADDR,false);
            objectlibrary.getlabel(lengthlab);
            cg.a_cmp_const_reg_label(exprasmlist,OS_ADDR,OC_EQ,0,left.location.register,lengthlab);
-           reference_reset_base(href,left.location.register,-sizeof(aint)*2);
+           reference_reset_base(href,left.location.register,-sizeof(aint));
            hregister:=cg.makeregsize(exprasmlist,left.location.register,OS_INT);
            cg.a_load_ref_reg(exprasmlist,OS_INT,OS_INT,href,hregister);
            cg.a_label(exprasmlist,lengthlab);
@@ -686,7 +686,10 @@ end.
 
 {
   $Log$
-  Revision 1.60  2004-06-20 08:55:29  florian
+  Revision 1.61  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.60  2004/06/20 08:55:29  florian
     * logs truncated
 
   Revision 1.59  2004/06/16 20:07:08  florian

+ 9 - 4
compiler/ncgmem.pas

@@ -582,6 +582,7 @@ implementation
     procedure tcgvecnode.pass_2;
 
       var
+         offsetdec,
          extraoffset : longint;
          t : tnode;
          href : treference;
@@ -638,9 +639,10 @@ implementation
 
               { in ansistrings/widestrings S[1] is p<w>char(S)[0] !! }
               if is_ansistring(left.resulttype.def) then
-                dec(location.reference.offset)
+                offsetdec:=1
               else
-                dec(location.reference.offset,2);
+                offsetdec:=2;
+              dec(location.reference.offset,offsetdec);
            end
          else if is_dynamic_array(left.resulttype.def) then
            begin
@@ -715,7 +717,7 @@ implementation
                               paramanager.allocparaloc(exprasmlist,paraloc2);
                               cg.a_param_const(exprasmlist,OS_INT,tordconstnode(right).value,paraloc2);
                               href:=location.reference;
-                              dec(href.offset,7);
+                              dec(href.offset,sizeof(aint)-offsetdec);
                               paramanager.allocparaloc(exprasmlist,paraloc1);
                               cg.a_param_ref(exprasmlist,OS_INT,href,paraloc1);
                               paramanager.freeparaloc(exprasmlist,paraloc1);
@@ -894,7 +896,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.93  2004-06-20 08:55:29  florian
+  Revision 1.94  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.93  2004/06/20 08:55:29  florian
     * logs truncated
 
   Revision 1.92  2004/06/16 20:07:08  florian

+ 6 - 11
compiler/ptconst.pas

@@ -632,15 +632,9 @@ implementation
                           begin
                             objectlibrary.getdatalabel(ll);
                             curconstSegment.concat(Tai_const.Create_sym(ll));
-                            { the actual structure starts at -12 from start label - CEC }
                             Consts.concat(tai_align.create(const_align(sizeof(aint))));
-                            { first write the maximum size }
-                            Consts.concat(Tai_const.Create_aint(strlength));
-                            { second write the real length }
-                            Consts.concat(Tai_const.Create_aint(strlength));
-                            { redondent with maxlength but who knows ... (PM) }
-                            { third write use count (set to -1 for safety ) }
                             Consts.concat(Tai_const.Create_aint(-1));
+                            Consts.concat(Tai_const.Create_aint(strlength));
                             Consts.concat(Tai_label.Create(ll));
                             getmem(ca,strlength+2);
                             move(strval^,ca^,strlength);
@@ -692,11 +686,9 @@ implementation
                           begin
                             objectlibrary.getdatalabel(ll);
                             curconstSegment.concat(Tai_const.Create_sym(ll));
-                            { the actual structure starts at -12 from start label - CEC }
                             Consts.concat(tai_align.create(const_align(sizeof(aint))));
-                            Consts.concat(Tai_const.Create_aint(strlength));
-                            Consts.concat(Tai_const.Create_aint(strlength));
                             Consts.concat(Tai_const.Create_aint(-1));
+                            Consts.concat(Tai_const.Create_aint(strlength));
                             Consts.concat(Tai_label.Create(ll));
                             for i:=0 to strlength-1 do
                               Consts.concat(Tai_const.Create_16bit(pcompilerwidestring(strval)^.data[i]));
@@ -1099,7 +1091,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.90  2004-07-03 14:06:35  daniel
+  Revision 1.91  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.90  2004/07/03 14:06:35  daniel
     * Compile fix
 
   Revision 1.89  2004/06/20 20:41:47  florian

+ 16 - 27
rtl/inc/astrings.inc

@@ -24,9 +24,8 @@
   AnsiString is defined as a 'silent' pchar :
   a pchar that points to :
 
-  @-12 : SizeInt for maximum size;
-  @-8  : SizeInt for size;
-  @-4  : SizeInt for reference count;
+  @-8  : SizeInt for reference count;
+  @-4  : SizeInt for size;
   @    : String + Terminating #0;
   Pchar(Ansistring) is a valid typecast.
   So AS[i] is converted to the address @AS+i-1.
@@ -38,9 +37,8 @@
 Type
   PAnsiRec = ^TAnsiRec;
   TAnsiRec = Packed Record
-    Maxlen,
-    len,
-    ref   : SizeInt;
+    Ref,
+    Len   : SizeInt;
     First : Char;
   end;
 
@@ -62,21 +60,15 @@ Function NewAnsiString(Len : SizeInt) : Pointer;
 }
 Var
   P : Pointer;
-  l : SizeInt;
 begin
-  l:=Len+AnsiRecLen;
-
   { request a multiple of 16 because the heap manager alloctes anyways chunks of 16 bytes }
-  if (l mod 16)<>0 then
-    inc(l,16-(l mod 16));
-  GetMem(P,l);
+  GetMem(P,Len+AnsiRecLen);
   If P<>Nil then
    begin
-     PAnsiRec(P)^.Maxlen:=l-AnsiRecLen;    { Maximal length }
-     PAnsiRec(P)^.Len:=0;         { Initial length }
      PAnsiRec(P)^.Ref:=1;         { Set reference count }
+     PAnsiRec(P)^.Len:=0;         { Initial length }
      PAnsiRec(P)^.First:=#0;      { Terminating #0 }
-     P:=P+FirstOff;               { Points to string now }
+     inc(p,firstoff);             { Points to string now }
    end;
   NewAnsiString:=P;
 end;
@@ -414,7 +406,7 @@ Procedure fpc_AnsiStr_SetLength (Var S : AnsiString; l : SizeInt);[Public,Alias
 }
 Var
   Temp : Pointer;
-  movelen, NewLen: SizeInt;
+  movelen : SizeInt;
 begin
   if (l>0) then
     begin
@@ -425,16 +417,10 @@ begin
        end
       else if (PAnsiRec(Pointer(S)-FirstOff)^.Ref = 1) then
         begin
-          if (PAnsiRec(Pointer(S)-FirstOff)^.Maxlen < L) then
-            begin
-              Dec(Pointer(S),FirstOff);
-              NewLen := (L+AnsiRecLen+15) and not(15) - AnsiRecLen;
-              reallocmem(pointer(S),AnsiRecLen+NewLen);
-              PAnsiRec(S)^.MaxLen := NewLen;
-              Inc(Pointer(S),FirstOff);
-            end;
-          PAnsiRec(Pointer(S)-FirstOff)^.Len := L;
-          PByte(Pointer(S)+L)^:=0;
+          Dec(Pointer(S),FirstOff);
+          if AnsiRecLen+L>MemSize(Pointer(s)) then
+            reallocmem(pointer(S),AnsiRecLen+L);
+          Inc(Pointer(S),FirstOff);
         end
       else
         begin
@@ -878,7 +864,10 @@ end;
 
 {
   $Log$
-  Revision 1.46  2004-07-02 21:21:09  peter
+  Revision 1.47  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.46  2004/07/02 21:21:09  peter
     * decr ref doesn't reset pointer
     * finalize resets pointer for astring,wstring
 

+ 13 - 22
rtl/inc/wstrings.inc

@@ -21,9 +21,8 @@
   WideString is defined as a 'silent' pwidechar :
   a pwidechar that points to :
 
-  @-12 : SizeInt for maximum size;
-  @-8  : SizeInt for size;
-  @-4  : SizeInt for reference count;
+  @-8  : SizeInt for reference count;
+  @-4  : SizeInt for size;
   @    : String + Terminating #0;
   Pwidechar(Widestring) is a valid typecast.
   So WS[i] is converted to the address @WS+i-1.
@@ -35,9 +34,8 @@
 Type
   PWideRec = ^TWideRec;
   TWideRec = Packed Record
-    Maxlen,
-    len,
-    ref   : SizeInt;
+    Ref,
+    Len   : SizeInt;
     First : WideChar;
   end;
 
@@ -151,14 +149,10 @@ Function NewWideString(Len : SizeInt) : Pointer;
 }
 Var
   P : Pointer;
-  l : SizeInt;
 begin
-  { request a multiple of 16 because the heap manager alloctes anyways chunks of 16 bytes }
-  L := (Len*sizeof(WideChar)+WideRecLen+15) and (not 15);
-  GetMem(P,l);
+  GetMem(P,Len*sizeof(WideChar)+WideRecLen);
   If P<>Nil then
    begin
-     PWideRec(P)^.Maxlen:=(l-WideRecLen) div sizeof(WideChar);    { Maximal length }
      PWideRec(P)^.Len:=0;         { Initial length }
      PWideRec(P)^.Ref:=1;         { Set reference count }
      PWideRec(P)^.First:=#0;      { Terminating #0 }
@@ -598,16 +592,10 @@ begin
        end
       else if (PWideRec(Pointer(S)-WideFirstOff)^.Ref = 1) then
         begin
-          if (PWideRec(Pointer(S)-WideFirstOff)^.Maxlen < L) then
-            begin
-              Dec(Pointer(S),WideFirstOff);
-              NewLen := (L*sizeof(WideChar)+WideRecLen+15) and (not 15);
-              reallocmem(pointer(S), NewLen);
-              PAnsiRec(S)^.MaxLen := (NewLen - WideRecLen) div sizeof(WideChar);
-              Inc(Pointer(S), WideFirstOff);
-            end;
-          PWideRec(Pointer(S)-WideFirstOff)^.Len := L;
-          PWord(Pointer(S)+L*sizeof(WideChar))^:=0;
+          Dec(Pointer(S),WideFirstOff);
+          if L*sizeof(WideChar)+WideRecLen>MemSize(Pointer(S)) then
+            reallocmem(pointer(S), L*sizeof(WideChar)+WideRecLen);
+          Inc(Pointer(S), WideFirstOff);
         end
       else
         begin
@@ -1044,7 +1032,10 @@ end;
 
 {
   $Log$
-  Revision 1.40  2004-07-02 21:21:09  peter
+  Revision 1.41  2004-07-12 17:58:19  peter
+    * remove maxlen field from ansistring/widestrings
+
+  Revision 1.40  2004/07/02 21:21:09  peter
     * decr ref doesn't reset pointer
     * finalize resets pointer for astring,wstring