CharacterArray.st
changeset 14592 cd1a3cff5d1c
parent 14555 2872ee4b234f
child 14606 1aaaa6d79e54
--- a/CharacterArray.st	Fri Dec 14 10:40:31 2012 +0100
+++ b/CharacterArray.st	Fri Dec 14 11:09:22 2012 +0100
@@ -326,7 +326,6 @@
     "
 ! !
 
-
 !CharacterArray class methodsFor:'pattern matching'!
 
 matchEscapeCharacter
@@ -1554,7 +1553,6 @@
 ! !
 
 
-
 !CharacterArray methodsFor:'character searching'!
 
 includesMatchCharacters
@@ -3791,14 +3789,16 @@
 utf8Decoded
     "Interpreting myself as an UTF-8 representation, decode and return the decoded string."
 
-    |in out is16Bit c|
-
-    is16Bit := false.
+    |in out|
+
+    self contains8BitCharacters ifFalse:[
+        "speed up common case"
+        ^ self.
+    ].
     out := CharacterWriteStream on:(String uninitializedNew:self size).
     in := self readStream.
     [in atEnd] whileFalse:[
-	c := Character utf8DecodeFrom:in.
-	out nextPut:c.
+        out nextPut:(Character utf8DecodeFrom:in).
     ].
     ^ out contents
 
@@ -3816,12 +3816,12 @@
       |utf8Encoding original readBack|
 
       1 to:16rFFFF do:[:ascii |
-	original := (Character value:ascii) asString.
-	utf8Encoding := original utf8Encoded.
-	readBack := utf8Encoding utf8Decoded.
-	readBack = original ifFalse:[
-	    self halt
-	]
+        original := (Character value:ascii) asString.
+        utf8Encoding := original utf8Encoded.
+        readBack := utf8Encoding utf8Decoded.
+        readBack = original ifFalse:[
+            self halt
+        ]
       ]
     "
 !
@@ -3853,13 +3853,20 @@
 utf8Encoded
     "Return my UTF-8 representation as a new String"
 
-    |s|
-
-    s := WriteStream on:(String uninitializedNew:self size).
+    |s sz|
+
+    self contains8BitCharacters ifFalse:[
+        "speed up common case"
+        ^ self.
+    ].
+    "We already know, that we need more space, just a rough estimation"
+    sz := self size.
+    s := WriteStream on:(String uninitializedNew:(sz+2+(sz//3))).
     s nextPutAllUtf8:self.
     ^ s contents
 
     "
+     'abcde1234' utf8Encoded
      'abcdeäöüß' utf8Encoded
     "
 
@@ -4311,7 +4318,6 @@
 ! !
 
 
-
 !CharacterArray methodsFor:'padded copying'!
 
 centerPaddedTo:newSize
@@ -4836,7 +4842,6 @@
     "Modified: 17.4.1997 / 12:50:23 / cg"
 ! !
 
-
 !CharacterArray methodsFor:'special string converting'!
 
 expandPlaceholdersWith:argArrayOrDictionary
@@ -6126,11 +6131,11 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.482 2012-12-12 22:54:34 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.483 2012-12-14 10:09:22 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.482 2012-12-12 22:54:34 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.483 2012-12-14 10:09:22 stefan Exp $'
 ! !
 
 CharacterArray initialize!