Skip to content

Commit 930ce39

Browse files
authored
Merge pull request #16486 from tesonep/remove-redundant-allocations-while-compiling
During compilation there are redundant allocation of collections
2 parents f9d07b7 + 82770c5 commit 930ce39

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Files/AbstractBinaryFileStream.class.st

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,19 @@ AbstractBinaryFileStream >> next: n into: aString startingAt: startIndex [
178178

179179
{ #category : 'writing' }
180180
AbstractBinaryFileStream >> next: amount putAll: aByteArray [
181+
182+
^ self next: amount putAll: aByteArray startingAt: 1
183+
]
184+
185+
{ #category : 'accessing' }
186+
AbstractBinaryFileStream >> next: amount putAll: aByteArray startingAt: startingIndex [
187+
181188
forWrite
182189
ifFalse: [ ^ self error: 'Cannot write a read-only file' ].
183190
[ File
184191
write: handle
185192
from: aByteArray
186-
startingAt: 1
193+
startingAt: startingIndex
187194
count: amount ]
188195
on: PrimitiveFailed
189196
do: [ (FileWriteError fileName: self name)

src/System-Sources/ChunkWriteStream.class.st

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,25 @@ ChunkWriteStream >> duplicateTerminatorMarkOn: aString [
3838

3939
| string start bangIndex newStringStream |
4040
string := aString asString.
41-
newStringStream := WriteStream on: (string species new: string size * 2).
4241
start := 1.
42+
bangIndex := string indexOf: self terminatorMark startingAt: start.
43+
44+
"We check the bang ahead, so we can avoid two allocations of the string!"
45+
(bangIndex = 0)
46+
ifTrue: [ ^ string copyWith: self terminatorMark ].
47+
48+
newStringStream := WriteStream on: (string species new: string size * 2).
4349

44-
[ (bangIndex := string indexOf: self terminatorMark startingAt: start) = 0 ]
50+
[ bangIndex = 0 ]
4551
whileFalse: [
4652
newStringStream
4753
next: bangIndex - start + 1
4854
putAll: string
4955
startingAt: start.
5056

5157
newStringStream nextPut: self terminatorMark. "double it"
52-
start := bangIndex + 1 ].
58+
start := bangIndex + 1.
59+
bangIndex := string indexOf: self terminatorMark startingAt: start ].
5360

5461
newStringStream
5562
next: string size - start + 1

0 commit comments

Comments
 (0)