[Pkg] The Trunk: Files-nice.73.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Mar 15 20:08:55 UTC 2010
Nicolas Cellier uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-nice.73.mcz
==================== Summary ====================
Name: Files-nice.73
Author: nice
Time: 15 March 2010, 9:08:50.767 pm
UUID: 8fbca3e6-5426-f548-bc7c-c076635533ab
Ancestors: Files-nice.72
Let #readInto:startingAt:count: handle the buffer and answer number of byte reads and always avoid a copy, and #next:into:startingAt: use it and eventually use a copy if number of bytes read less than requested count.
=============== Diff against Files-nice.72 ===============
Item was changed:
----- Method: StandardFileStream>>readInto:startingAt:count: (in category 'read, write, position') -----
readInto: byteArray startingAt: startIndex count: count
"Read into the given array as specified, and return the count
actually transferred. index and count are in units of bytes or
longs depending on whether the array is Bitmap, String or ByteArray"
+ | nRead newN newStartIndex |
+ collection
+ ifNil: [
+ newN := count.
+ newStartIndex := startIndex ]
+ ifNotNil: [
+ byteArray class isBytes
+ ifFalse: [
+ position < readLimit ifTrue: [ self flushReadBuffer ].
+ newN := count.
+ newStartIndex := startIndex ]
+ ifTrue: [
+ | available |
+ (available := readLimit - position) > 0
+ ifFalse: [ available := 0 ]
+ ifTrue: [
+ | bufferedCount |
+ bufferedCount := count min: available.
+ byteArray
+ replaceFrom: startIndex
+ to: startIndex + bufferedCount - 1
+ with: collection
+ startingAt: position + 1.
+ position := position + bufferedCount.
+ bufferedCount = count ifTrue: [ ^count ] ].
+ newN := count - available.
+ newStartIndex := startIndex + available ] ].
+ nRead := self primRead: fileID into: byteArray startingAt: newStartIndex count: newN.
+ ^nRead + (count - newN)!
- ^(self next: count into: byteArray startingAt: startIndex) size - startIndex + 1 min: count
- !
Item was changed:
----- Method: StandardFileStream>>next:into:startingAt: (in category 'read, write, position') -----
next: n into: aString startingAt: startIndex
"Read n bytes into the given string.
Return aString or a partial copy if less than
n elements have been read."
+ | count |
+ count := self readInto: aString startingAt: startIndex count: n.
+ count = n
- | count newN newStartIndex |
- collection
- ifNil: [
- newN := n.
- newStartIndex := startIndex ]
- ifNotNil: [
- aString class isBytes
- ifFalse: [
- position < readLimit ifTrue: [ self flushReadBuffer ].
- newN := n.
- newStartIndex := startIndex ]
- ifTrue: [
- | available |
- (available := readLimit - position) > 0
- ifFalse: [ available := 0 ]
- ifTrue: [
- | bufferedCount |
- bufferedCount := n min: available.
- aString
- replaceFrom: startIndex
- to: startIndex + bufferedCount - 1
- with: collection
- startingAt: position + 1.
- position := position + bufferedCount.
- bufferedCount = n ifTrue: [ ^aString ] ].
- newN := n - available.
- newStartIndex := startIndex + available ] ].
- count := self primRead: fileID into: aString
- startingAt: newStartIndex count: newN.
- count = newN
ifTrue:[ ^aString ]
+ ifFalse:[ ^aString copyFrom: 1 to: startIndex + count - 1 ]!
- ifFalse:[ ^aString copyFrom: 1 to: newStartIndex + count - 1 ]!
More information about the Packages
mailing list