The Inbox: Collections-ul.933.mcz

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

The Inbox: Collections-ul.933.mcz

commits-2
Levente Uzonyi uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-ul.933.mcz

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

Name: Collections-ul.933
Author: ul
Time: 31 March 2021, 2:17:52.141067 am
UUID: b290ad2c-2ed0-4d46-b2fe-12545bf5f31c
Ancestors: Collections-ul.932

- use #ofSize: instead of #new: in SequenceableCollection class >> new:streamContents:, so that it creates a stream on a non-empty collection even if the receiver is OrderedCollection.

=============== Diff against Collections-ul.932 ===============

Item was changed:
  ----- Method: SequenceableCollection class>>new:streamContents: (in category 'stream creation') -----
  new: newSize streamContents: blockWithArg
 
  | stream originalContents |
+ stream := WriteStream on: (self ofSize: newSize).
- stream := WriteStream on: (self new: newSize).
  blockWithArg value: stream.
  originalContents := stream originalContents.
+ ^originalContents size =  stream position
+ ifTrue: [ originalContents ]
+ ifFalse: [ stream contents ]!
- originalContents size =  stream position
- ifTrue: [ ^originalContents ]
- ifFalse: [ ^stream contents ]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ul.933.mcz

marcel.taeumel
+1 I suppose =)

It's faster then:

[OrderedCollection streamContents: [:s | s nextPut: #apple]] bench  

BEFORE: '2,630,000 per second. 380 nanoseconds per run. 16.13677 % GC time.'
AFTER: '3,990,000 per second. 251 nanoseconds per run. 15.89682 % GC time.'

Best,
Marcel

Am 31.03.2021 02:19:03 schrieb [hidden email] <[hidden email]>:

Levente Uzonyi uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-ul.933.mcz

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

Name: Collections-ul.933
Author: ul
Time: 31 March 2021, 2:17:52.141067 am
UUID: b290ad2c-2ed0-4d46-b2fe-12545bf5f31c
Ancestors: Collections-ul.932

- use #ofSize: instead of #new: in SequenceableCollection class >> new:streamContents:, so that it creates a stream on a non-empty collection even if the receiver is OrderedCollection.

=============== Diff against Collections-ul.932 ===============

Item was changed:
----- Method: SequenceableCollection class>>new:streamContents: (in category 'stream creation') -----
new: newSize streamContents: blockWithArg

| stream originalContents |
+ stream := WriteStream on: (self ofSize: newSize).
- stream := WriteStream on: (self new: newSize).
blockWithArg value: stream.
originalContents := stream originalContents.
+ ^originalContents size = stream position
+ ifTrue: [ originalContents ]
+ ifFalse: [ stream contents ]!
- originalContents size = stream position
- ifTrue: [ ^originalContents ]
- ifFalse: [ ^stream contents ]!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ul.933.mcz

Christoph Thiede

Hi Levente,


so what is now the official interface for creating a valid collection of any kind of a certain size n? Shall we always use #ofSize:? Is this something that should be documented in the release notes?


Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Dienstag, 27. April 2021 17:07:18
An: squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Collections-ul.933.mcz
 
+1 I suppose =)

It's faster then:

[OrderedCollection streamContents: [:s | s nextPut: #apple]] bench  

BEFORE: '2,630,000 per second. 380 nanoseconds per run. 16.13677 % GC time.'
AFTER: '3,990,000 per second. 251 nanoseconds per run. 15.89682 % GC time.'

Best,
Marcel

Am 31.03.2021 02:19:03 schrieb [hidden email] <[hidden email]>:

Levente Uzonyi uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-ul.933.mcz

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

Name: Collections-ul.933
Author: ul
Time: 31 March 2021, 2:17:52.141067 am
UUID: b290ad2c-2ed0-4d46-b2fe-12545bf5f31c
Ancestors: Collections-ul.932

- use #ofSize: instead of #new: in SequenceableCollection class >> new:streamContents:, so that it creates a stream on a non-empty collection even if the receiver is OrderedCollection.

=============== Diff against Collections-ul.932 ===============

Item was changed:
----- Method: SequenceableCollection class>>new:streamContents: (in category 'stream creation') -----
new: newSize streamContents: blockWithArg

| stream originalContents |
+ stream := WriteStream on: (self ofSize: newSize).
- stream := WriteStream on: (self new: newSize).
blockWithArg value: stream.
originalContents := stream originalContents.
+ ^originalContents size = stream position
+ ifTrue: [ originalContents ]
+ ifFalse: [ stream contents ]!
- originalContents size = stream position
- ifTrue: [ ^originalContents ]
- ifFalse: [ ^stream contents ]!




Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ul.933.mcz

Levente Uzonyi
Hi Christoph,

On Sat, 1 May 2021, Thiede, Christoph wrote:

>
> Hi Levente,
>
>
> so what is now the official interface for creating a valid collection of any kind of a certain size n? Shall we always use #ofSize:? Is this something that should be documented in the release notes?

There's no such interface for "a valid collection of any kind", and it's
not possible to create one, because we have many different collections
with different properties.
For that reason, Collection doesn't implement #new:, however it inherits
the method from Behavior, but that is not ideal.

#new: is actually there to support variable classes, so it works well for
ArrayedCollections, which are variable classes.
Some collections, like Set, Heap, Dictionary, etc. use it to take a
desired initial capacity. Unfortunately, OrderedCollection also follows
that pattern.
Some collections cannot implement #new:, like Interval or CharacterSet.

To answer your question, for ArrayedCollections, the method you asked
about is #new:.
OrderedCollection is a resizable ArrayedCollection: the collection
an OrderedCollection encapsulates (array) is always an ArrayedCollection.
Its API is similar to ArrayedCollection's but it is not exactly the same.
#new: is different.

As I wrote in another email recently, #new: could have been implemented
to create a non-empty collection unless the argument is 0. But for some
reason it wasn't.

#ofSize:, according to its method comment, was created to work around
that difference:

  "Create a new collection of size n with nil as its elements.
  This method exists because OrderedCollection new: n creates an
  empty collection,  not one of size n."

IMO the best would be to eliminate that difference, but it may be too late
now, because that would involve breaking all programs having the snippet

  OrderedCollection new: x

There are 97 potential methods with that pattern in my Trunk image (two of
those are false positives: the implementors of #ofSize:):

CurrentReadOnlySourceFiles cacheDuring: [
  | regex |
  regex := ('({1})\\s+new\\:' format: { (OrderedCollection withAllSubclasses collect: #name) joinSeparatedBy: '|' }) asRegex.
  SystemNavigation browseAllSelect: [ :method |
  regex search: method getSource asString  ] ].


Levente

>
>
> Best,
>
> Christoph
>
> _________________________________________________________________________________________________________________________________________________________________________________________________________________________________
> Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
> Gesendet: Dienstag, 27. April 2021 17:07:18
> An: squeak-dev
> Betreff: Re: [squeak-dev] The Inbox: Collections-ul.933.mcz  
> +1 I suppose =)
> It's faster then:
>
> [OrderedCollection streamContents: [:s | s nextPut: #apple]] bench  
>
> BEFORE: '2,630,000 per second. 380 nanoseconds per run. 16.13677 % GC time.'
> AFTER: '3,990,000 per second. 251 nanoseconds per run. 15.89682 % GC time.'
>
> Best,
> Marcel
>
>       Am 31.03.2021 02:19:03 schrieb [hidden email] <[hidden email]>:
>
>       Levente Uzonyi uploaded a new version of Collections to project The Inbox:
>       http://source.squeak.org/inbox/Collections-ul.933.mcz
>
>       ==================== Summary ====================
>
>       Name: Collections-ul.933
>       Author: ul
>       Time: 31 March 2021, 2:17:52.141067 am
>       UUID: b290ad2c-2ed0-4d46-b2fe-12545bf5f31c
>       Ancestors: Collections-ul.932
>
>       - use #ofSize: instead of #new: in SequenceableCollection class >> new:streamContents:, so that it creates a stream on a non-empty collection even if the receiver is OrderedCollection.
>
>       =============== Diff against Collections-ul.932 ===============
>
>       Item was changed:
>       ----- Method: SequenceableCollection class>>new:streamContents: (in category 'stream creation') -----
>       new: newSize streamContents: blockWithArg
>
>       | stream originalContents |
>       + stream := WriteStream on: (self ofSize: newSize).
>       - stream := WriteStream on: (self new: newSize).
>       blockWithArg value: stream.
>       originalContents := stream originalContents.
>       + ^originalContents size = stream position
>       + ifTrue: [ originalContents ]
>       + ifFalse: [ stream contents ]!
>       - originalContents size = stream position
>       - ifTrue: [ ^originalContents ]
>       - ifFalse: [ ^stream contents ]!
>
>
>
>