String.st
changeset 3085 772b3e842c88
parent 2954 a2f437a0483a
child 3111 a23fa6d08ce7
--- a/String.st	Sun Nov 02 19:30:50 1997 +0100
+++ b/String.st	Sun Nov 02 19:34:49 1997 +0100
@@ -10,8 +10,6 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.1.9 on 22-aug-1997 at 5:33:16 pm'                  !
-
 CharacterArray subclass:#String
 	instanceVariableNames:''
 	classVariableNames:''
@@ -298,9 +296,21 @@
 !String class methodsFor:'binary storage'!
 
 binaryDefinitionFrom:stream manager:manager
-    "read a binary representation from stream."
+    "read a binary representation from stream. This is only invoked
+     for long strings. Short strings are stored with 1byte length."
+
+    |s len|
 
-    ^ (stream next:(stream nextNumber: 4)) asString
+    "take care of subclasses ..."
+    ((self == String) or:[self == Symbol]) ifTrue:[
+        len := stream nextNumber:4.
+        s := String basicNew:len.
+        stream nextBytes:len into:s startingAt:1.
+        ^ s
+    ].
+    ^ super binaryDefinitionFrom:stream manager:manager
+
+    "Modified: / 2.11.1997 / 16:18:37 / cg"
 ! !
 
 !String class methodsFor:'queries'!
@@ -511,6 +521,39 @@
 %}
 ! !
 
+!String methodsFor:'binary storage'!
+
+storeBinaryDefinitionOn:stream manager:manager
+    "append a binary representation of the receiver onto stream.
+     Redefined since short Strings can be stored with a special type code 
+     in a more compact way.
+     This is an internal interface for the binary storage mechanism."
+
+    |myClass myBasicSize|
+
+    "/ not for subclasses with named instVars.
+    (myClass := self class) instSize ~~ 0 ifTrue:[
+        ^ super storeBinaryDefinitionOn:stream manager:manager
+    ].
+
+    myBasicSize := self basicSize.
+
+    "/ can use a more compact representation;
+    "/ but not for subclasses ...
+
+    ((myClass == String) 
+    and:[myBasicSize <= 255]) ifTrue:[
+        "/ special encoding: <codeForString> <len> <bytes> ...
+        stream nextPut:(manager codeForString); nextPut:myBasicSize.
+    ] ifFalse:[
+        manager putIdOfClass:myClass on:stream.
+        stream nextNumber:4 put:myBasicSize.
+    ].
+    stream nextPutBytes:myBasicSize from:self startingAt:1.
+
+    "Modified: / 2.11.1997 / 15:28:56 / cg"
+! !
+
 !String methodsFor:'character searching'!
 
 identityIndexOf:aCharacter
@@ -2516,5 +2559,5 @@
 !String class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.105 1997-09-18 20:19:24 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.106 1997-11-02 18:34:49 cg Exp $'
 ! !