The Inbox: Files-ul.80.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Files-ul.80.mcz

commits-2
A new version of Files was added to project The Inbox:
http://source.squeak.org/inbox/Files-ul.80.mcz

==================== Summary ====================

Name: Files-ul.80
Author: ul
Time: 31 March 2010, 4:17:28.904 am
UUID: 30200227-9fc6-f145-b440-16541e7b855b
Ancestors: Files-nice.79

- fixed StandardFileStream's #upTo: and #upToAnyOf:do:. They don't use recursion anymore. They also use the return value of #readInto:startingAt:count: to detect the end of the file instead of #atEnd.

=============== Diff against Files-nice.79 ===============

Item was changed:
  ----- Method: StandardFileStream>>upTo: (in category 'read, write, position') -----
+ upTo: delimiter
+
+ | pos |
- upTo: delim
- "Fast version to speed up nextChunk"
- | pos buffer count |
  collection ifNotNil: [
  (position < readLimit and: [
+ (pos := collection indexOf: delimiter startingAt: position + 1) <= readLimit and: [
- (pos := collection indexOf: delim startingAt: position + 1) <= readLimit and: [
  pos > 0 ] ]) ifTrue: [
  ^collection copyFrom: position + 1 to: (position := pos) - 1 ] ].
+ ^self collectionSpecies streamContents: [ :stream |
+ | buffer bytesRead |
+ buffer := collection
+ ifNil: [ self collectionSpecies new: 2000 ]
+ ifNotNil: [
+ position < readLimit ifTrue: [
+ stream next: readLimit - position putAll: collection startingAt: position + 1.
+ position := readLimit ].
+ collection ].
+ [
+ bytesRead := self readInto: buffer startingAt: 1 count: buffer size.
+ ((pos := buffer indexOf: delimiter startingAt: 1) = 0 or: [ pos > bytesRead ])
+ ifTrue: [
+ stream next: bytesRead putAll: buffer startingAt: 1.
+ bytesRead > 0 "Try again if we could read something last time." ]
+ ifFalse: [
+ stream next: pos - 1 putAll: buffer startingAt: 1.
+ self skip: pos - bytesRead.
+ false "Found the delimiter." ] ] whileTrue ]!
- pos := self position.
- buffer := self next: 2000.
- (count := buffer indexOf: delim) > 0 ifTrue:
- ["Found the delimiter part way into buffer"
- self position: pos + count.
- ^ buffer copyFrom: 1 to: count - 1].
- self atEnd ifTrue:
- ["Never found it, and hit end of file"
- ^ buffer].
- "Never found it, but there's more..."
- ^ buffer , (self upTo: delim)!

Item was changed:
  ----- Method: StandardFileStream>>upToAnyOf:do: (in category 'read, write, position') -----
  upToAnyOf: delimiters do: aBlock
+
+ | pos |
- "Fast version to speed up nextChunk"
- | pos buffer count result |
  collection ifNotNil: [
  (position < readLimit and: [
+ (pos := collection indexOfAnyOf: delimiters startingAt: position + 1) <= readLimit and: [
+ pos > 0 ] ]) ifTrue: [
+ | result |
+ result := collection copyFrom: position + 1 to: (position := pos) - 1 .
+ aBlock value: (collection at: position).
- (count := collection indexOfAnyOf: delimiters startingAt: position + 1) <= readLimit and: [
- count > 0 ] ]) ifTrue: [
- result := collection copyFrom: position + 1 to: (position := count) - 1.
- aBlock value: (collection at: count).
  ^result ] ].
+ ^self collectionSpecies streamContents: [ :stream |
+ | buffer bytesRead |
+ buffer := collection
+ ifNil: [ self collectionSpecies new: 2000 ]
+ ifNotNil: [
+ position < readLimit ifTrue: [
+ stream next: readLimit - position putAll: collection startingAt: position + 1.
+ position := readLimit ].
+ collection ].
+ [
+ bytesRead := self readInto: buffer startingAt: 1 count: buffer size.
+ ((pos := buffer indexOfAnyOf: delimiters startingAt: 1) = 0 or: [ pos > bytesRead ])
+ ifTrue: [
+ stream next: bytesRead putAll: buffer startingAt: 1.
+ bytesRead > 0 "Try again if we could read something last time." ]
+ ifFalse: [
+ stream next: pos - 1 putAll: buffer startingAt: 1.
+ self skip: pos - bytesRead.
+ false "Found the delimiter." ] ] whileTrue.
+ bytesRead = 0 ifFalse: [
+ aBlock value: (buffer at: pos) ] ]!
- pos := self position.
- buffer := self next: 2000.
- (count := buffer indexOfAnyOf: delimiters) > 0 ifTrue:
- ["Found one of the delimiters part way into buffer"
- self position: pos + count.
- aBlock value: (buffer at: count).
- ^ buffer copyFrom: 1 to: count - 1].
- self atEnd ifTrue:
- ["Never found it, and hit end of file"
- ^ buffer].
- "Never found it, but there's more..."
- ^ buffer , (self upToAnyOf: delimiters do: aBlock)!