Skip to content

Commit

Permalink
https://github.com/pharo-project/pharo/issues/5029
Browse files Browse the repository at this point in the history
Improve the efficiency of the loop in ChunkWriteStream>>#nextPut: and WrtiteStream>>#nextChunkPut:
Add #next:putAll:startingAt: to SourceFile and SourceFileCharacterReadWriteStream
  • Loading branch information
Sven Van Caekenberghe committed Oct 29, 2019
1 parent 16ce77b commit 2d9d48d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 27 deletions.
26 changes: 14 additions & 12 deletions src/CodeExport/ChunkWriteStream.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ ChunkWriteStream >> nextChunkPut: aString [

{ #category : #accessing }
ChunkWriteStream >> nextPut: aString [
"Append the argument, aString, to the receiver, doubling embedded terminators."

| i remainder terminator |
terminator := $!.
remainder := aString asString.
[(i := remainder indexOf: terminator) = 0] whileFalse:
[decoratedStream nextPutAll: (remainder copyFrom: 1 to: i).
decoratedStream nextPut: terminator. "double imbedded terminators"
remainder := remainder copyFrom: i+1 to: remainder size].
decoratedStream nextPutAll: remainder.
decoratedStream nextPut: terminator.
decoratedStream flush.
"Append the argument, aString, to the receiver, doubling embedded ! terminators and adding a extra one"

| string start bangIndex |
string := aString asString.
start := 1.
[ (bangIndex := string indexOf: self terminatorMark startingAt: start) = 0 ]
whileFalse: [
decoratedStream next: bangIndex - start + 1 putAll: string startingAt: start.
self bang. "double it"
start := bangIndex + 1 ].
decoratedStream next: string size - start + 1 putAll: string startingAt: start.
self bang. "one extra"
decoratedStream flush

]

{ #category : #accessing }
Expand Down
30 changes: 15 additions & 15 deletions src/CodeExport/WriteStream.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ Extension { #name : #WriteStream }

{ #category : #'*CodeExport' }
WriteStream >> nextChunkPut: aString [
"Append the argument, aString, to the receiver, doubling embedded terminators."
"Append the argument, aString, to the receiver, doubling embedded ! terminators and adding a extra one"

| i remainder terminator |
terminator := $!.
remainder := aString asString.
[(i := remainder indexOf: terminator) = 0] whileFalse:
[self nextPutAll: (remainder copyFrom: 1 to: i).
self nextPut: terminator. "double imbedded terminators"
remainder := remainder copyFrom: i+1 to: remainder size].
self nextPutAll: remainder.
aString asString includesUnifiedCharacter ifTrue: [
self nextPut: terminator.
self nextPutAll: ']lang['.
aString asString writeLeadingCharRunsOn: self.
| string start bangIndex |
string := aString asString.
start := 1.
[ (bangIndex := string indexOf: $! startingAt: start) = 0 ]
whileFalse: [
self next: bangIndex - start + 1 putAll: string startingAt: start.
self nextPut: $!. "double it"
start := bangIndex + 1 ].
self next: string size - start + 1 putAll: string startingAt: start.
string includesUnifiedCharacter ifTrue: [
self nextPut: $!; nextPutAll: ']lang['.
string writeLeadingCharRunsOn: self.
].
self nextPut: terminator.
self flush.
self nextPut: $!. "one extra"
self flush
]

{ #category : #'*CodeExport' }
Expand Down
7 changes: 7 additions & 0 deletions src/System-Sources/SourceFile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ SourceFile >> next: anInteger [
^ stream next: anInteger
]

{ #category : #accessing }
SourceFile >> next: anInteger putAll: aString startingAt: startIndex [

stream next: anInteger putAll: aString startingAt: startIndex

]

{ #category : #'fileIn/Out' }
SourceFile >> nextChunk [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ SourceFileCharacterReadWriteStream >> next: anInteger [
^ readStream next: anInteger
]

{ #category : #accessing }
SourceFileCharacterReadWriteStream >> next: anInteger putAll: aString startingAt: startIndex [

^ writeStream next: anInteger putAll: aString startingAt: startIndex
]

{ #category : #accessing }
SourceFileCharacterReadWriteStream >> nextPut: aCharacter [

Expand Down

0 comments on commit 2d9d48d

Please sign in to comment.