2009/10/12 Henrik Johansen <henrik.s.johansen@veloxit.no>
Hi, just did a small test of a faster storeOn: for ByteStrings (using next:putAll:startingAt: for sequences not containing quotes, instead of nextPut: for each character ), and ran into a weird quirk. When writing to disk (on Windows), the old storeOn: would result in storing the ø's in the string below as F8, while with storeOn2: they are stored as C3 B8. (Haven't looked at exactly why they're saved differently.) As far as I can tell from a google search, F8 is ascii encoding, and C3 B8 is UTF8 encoding.
Could this be a cause for the "invalid UTF8 character"-errors we've been seeing sporadically?
Attached a changeset with storeOn2: , below is the workspace I used.
Cheers, Henry
str :=
'asdfasdfadfadfrgjn''fgoibocbxlgjsrgoihrgohgfn''cx,bmxnbøzghøfhzødfhxcvnzdfljfoaurgaorhr8htg0ae8gofhef08hasovhdfhøxo''vh89ah4f9aw8hf'.
str storeOn: (FileStream newFileNamed: 'test22.txt'). Time millisecondsToRun: [|fs| fs := FileStream oldFileNamed: 'test22.txt'. 50000 timesRepeat: [str storeOn: fs]. fs close]. 23494 22869
str storeOn2: (FileStream newFileNamed: 'test2.txt'). Time millisecondsToRun: [|fs| fs := FileStream oldFileNamed: 'test2.txt'. 50000 timesRepeat: [str storeOn2: fs]. fs close]. 1303 1383
WOW!!! I run it here in a Windows XP 1GB RAM and these are the results: str storeOn: (FileStream newFileNamed: 'test22.txt'). Time millisecondsToRun: [|fs| fs := FileStream oldFileNamed: 'test22.txt'. 50000 timesRepeat: [str storeOn: fs]. fs close]. 84022 str storeOn2: (FileStream newFileNamed: 'test2.txt'). Time millisecondsToRun: [|fs| fs := FileStream oldFileNamed: 'test2.txt'. 50000 timesRepeat: [str storeOn2: fs]. fs close]. 4990 BIG DIFFERENCE
'From Pharo1.0beta of 16 May 2008 [Latest update: #10470] on 12 October 2009 at 2:31:08 pm'!
!ByteString methodsFor: 'printing' stamp: 'HenrikSperreJohansen 10/12/2009 14:30'! storeOn2: aStream "Print inside string quotes, doubling inbedded quotes." | ix startIx| aStream nextPut: $'. startIx := 1. [(ix := self indexOf: $' startingAt: startIx) > 0 ] whileTrue: [ aStream next: ix +1 - startIx putAll: self startingAt: startIx. aStream nextPut: $'. startIx := ix +1].
aStream next: self size +1 - startIx putAll: self startingAt: startIx. aStream nextPut: $'. ! !
!ByteString methodsFor: 'printing' stamp: 'HenrikSperreJohansen 10/12/2009 14:30'! storeString2 "Answer a String representation of the receiver from which the receiver can be reconstructed." |result ws | result := String new: self size +2. ws := result writeStream. self storeOn2: ws. ^ws position = result size ifTrue: [result] ifFalse: [ws contents] ! !
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project