The Inbox: System-ct.1133.mcz

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

The Inbox: System-ct.1133.mcz

commits-2
Christoph Thiede uploaded a new version of System to project The Inbox:
http://source.squeak.org/inbox/System-ct.1133.mcz

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

Name: System-ct.1133
Author: ct
Time: 3 February 2020, 11:55:06.856675 pm
UUID: bd5c789a-39d3-574b-aa2a-0f900b3a8009
Ancestors: System-cmm.1131

Fix execution-around pattern to forward return value in some during methods

So that
        Utilities useAuthorName: 'Squeak' during: [Utilities authorName]
yields
        'Squeak'
but not
        Utilities.

=============== Diff against System-cmm.1131 ===============

Item was changed:
  ----- Method: Preferences class>>setFlag:toValue:during: (in category 'get/set - flags') -----
  setFlag: prefSymbol toValue: aBoolean during: aBlock
  "Set the flag to the given value for the duration of aBlock"
 
  (self valueOfFlag: prefSymbol) in: [:previous |
  self setFlag: prefSymbol toValue: aBoolean.
+ ^ aBlock ensure: [self setFlag: prefSymbol toValue: previous]].!
- aBlock ensure: [self setFlag: prefSymbol toValue: previous]].!

Item was changed:
  ----- Method: Preferences class>>setPreference:toValue:during: (in category 'get/set') -----
  setPreference: prefSymbol toValue: anObject during: aBlock
 
  (self valueOfPreference: prefSymbol) in: [:previous |
  self setPreference: prefSymbol toValue: anObject.
+ ^ aBlock ensure: [self setPreference: prefSymbol toValue: previous]]!
- aBlock ensure: [self setPreference: prefSymbol toValue: previous]].!

Item was changed:
  ----- Method: Utilities class>>useAuthorInitials:during: (in category 'identification') -----
  useAuthorInitials: temporaryAuthorInitials during: aBlock
 
  | originalAuthorInitials |
  originalAuthorInitials := AuthorInitials.
+ [ AuthorInitials := temporaryAuthorInitials.
+ ^ aBlock value ]
- [
- AuthorInitials := temporaryAuthorInitials.
- aBlock value ]
  ensure: [ AuthorInitials := originalAuthorInitials ]
  !

Item was changed:
  ----- Method: Utilities class>>useAuthorName:during: (in category 'identification') -----
  useAuthorName: temporaryAuthorName during: aBlock
 
  | originalAuthorName |
  originalAuthorName := AuthorName.
+ [ AuthorName := temporaryAuthorName.
+ ^ aBlock value ]
- [
- AuthorName := temporaryAuthorName.
- aBlock value ]
  ensure: [ AuthorName := originalAuthorName ]
  !


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: System-ct.1133.mcz

Levente Uzonyi
Hi Christoph,

On Mon, 3 Feb 2020, [hidden email] wrote:

> Christoph Thiede uploaded a new version of System to project The Inbox:
> http://source.squeak.org/inbox/System-ct.1133.mcz
>
> ==================== Summary ====================
>
> Name: System-ct.1133
> Author: ct
> Time: 3 February 2020, 11:55:06.856675 pm
> UUID: bd5c789a-39d3-574b-aa2a-0f900b3a8009
> Ancestors: System-cmm.1131
>
> Fix execution-around pattern to forward return value in some during methods
>
> So that
> Utilities useAuthorName: 'Squeak' during: [Utilities authorName]
> yields
> 'Squeak'
> but not
> Utilities.
>
> =============== Diff against System-cmm.1131 ===============
>
> Item was changed:
>  ----- Method: Preferences class>>setFlag:toValue:during: (in category 'get/set - flags') -----
>  setFlag: prefSymbol toValue: aBoolean during: aBlock
>   "Set the flag to the given value for the duration of aBlock"
>
>   (self valueOfFlag: prefSymbol) in: [:previous |
>   self setFlag: prefSymbol toValue: aBoolean.
> + ^ aBlock ensure: [self setFlag: prefSymbol toValue: previous]].!
> - aBlock ensure: [self setFlag: prefSymbol toValue: previous]].!
>
> Item was changed:
>  ----- Method: Preferences class>>setPreference:toValue:during: (in category 'get/set') -----
>  setPreference: prefSymbol toValue: anObject during: aBlock
>
>   (self valueOfPreference: prefSymbol) in: [:previous |
>   self setPreference: prefSymbol toValue: anObject.
> + ^ aBlock ensure: [self setPreference: prefSymbol toValue: previous]]!
> - aBlock ensure: [self setPreference: prefSymbol toValue: previous]].!
>
> Item was changed:
>  ----- Method: Utilities class>>useAuthorInitials:during: (in category 'identification') -----
>  useAuthorInitials: temporaryAuthorInitials during: aBlock
>
>   | originalAuthorInitials |
>   originalAuthorInitials := AuthorInitials.
> + [ AuthorInitials := temporaryAuthorInitials.
> + ^ aBlock value ]

Returning from inside a block has some extra costs. You can achieve the
same thing without the overhead by returning what #ensure: returns:

  ^[ AuthorInitials := temporaryAuthorInitials.
  aBlock value ]


Levente

> + [ AuthorInitials := temporaryAuthorInitials.
> + ^ aBlock value ]


> - [
> - AuthorInitials := temporaryAuthorInitials.
> - aBlock value ]
>   ensure: [ AuthorInitials := originalAuthorInitials ]
>   !
>
> Item was changed:
>  ----- Method: Utilities class>>useAuthorName:during: (in category 'identification') -----
>  useAuthorName: temporaryAuthorName during: aBlock
>
>   | originalAuthorName |
>   originalAuthorName := AuthorName.
> + [ AuthorName := temporaryAuthorName.
> + ^ aBlock value ]
> - [
> - AuthorName := temporaryAuthorName.
> - aBlock value ]
>   ensure: [ AuthorName := originalAuthorName ]
>   !

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: System-ct.1133.mcz

Christoph Thiede

Hi Levente,


Returning from inside a block has some extra costs. You can achieve the same thing without the overhead by returning what #ensure: returns:


Wow, thanks for the hint! I made some quick measurements and the results were surprising:

c := Object newSubclass.
c compile: 'foo ^ [2 + 3] ensure: []'.
c compile: 'bar [^ 2 + 3] ensure: []'.
o := c new.
[o foo] bench. "60 ns"
[o bar] bench. "700 ns"

What's the reason? The second version calls #methodReturnTop, why is this so expensive? From my naive understanding, one call to #findNextUnwindContextUpTo: should not be significantly slower than two calls to #resume:?
However, it's interesting ... Will patch this commit soon.

Best,
Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Levente Uzonyi <[hidden email]>
Gesendet: Dienstag, 4. Februar 2020 13:33 Uhr
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: System-ct.1133.mcz
 
Hi Christoph,

On Mon, 3 Feb 2020, [hidden email] wrote:

> Christoph Thiede uploaded a new version of System to project The Inbox:
> http://source.squeak.org/inbox/System-ct.1133.mcz
>
> ==================== Summary ====================
>
> Name: System-ct.1133
> Author: ct
> Time: 3 February 2020, 11:55:06.856675 pm
> UUID: bd5c789a-39d3-574b-aa2a-0f900b3a8009
> Ancestors: System-cmm.1131
>
> Fix execution-around pattern to forward return value in some during methods
>
> So that
>        Utilities useAuthorName: 'Squeak' during: [Utilities authorName]
> yields
>        'Squeak'
> but not
>        Utilities.
>
> =============== Diff against System-cmm.1131 ===============
>
> Item was changed:
>  ----- Method: Preferences class>>setFlag:toValue:during: (in category 'get/set - flags') -----
>  setFlag: prefSymbol toValue: aBoolean during: aBlock
>        "Set the flag to the given value for the duration of aBlock"
>
>        (self valueOfFlag: prefSymbol) in: [:previous |
>                self setFlag: prefSymbol toValue: aBoolean.
> +              ^ aBlock ensure: [self setFlag: prefSymbol toValue: previous]].!
> -              aBlock ensure: [self setFlag: prefSymbol toValue: previous]].!
>
> Item was changed:
>  ----- Method: Preferences class>>setPreference:toValue:during: (in category 'get/set') -----
>  setPreference: prefSymbol toValue: anObject during: aBlock
>
>        (self valueOfPreference: prefSymbol) in: [:previous |
>                self setPreference: prefSymbol toValue: anObject.
> +              ^ aBlock ensure: [self setPreference: prefSymbol toValue: previous]]!
> -              aBlock ensure: [self setPreference: prefSymbol toValue: previous]].!
>
> Item was changed:
>  ----- Method: Utilities class>>useAuthorInitials:during: (in category 'identification') -----
>  useAuthorInitials: temporaryAuthorInitials during: aBlock
>
>        | originalAuthorInitials |
>        originalAuthorInitials := AuthorInitials.
> +      [ AuthorInitials := temporaryAuthorInitials.
> +      ^ aBlock value ]

Returning from inside a block has some extra costs. You can achieve the
same thing without the overhead by returning what #ensure: returns:

         ^[ AuthorInitials := temporaryAuthorInitials.
         aBlock value ]


Levente

> +      [ AuthorInitials := temporaryAuthorInitials.
> +      ^ aBlock value ]


> -      [
> -              AuthorInitials := temporaryAuthorInitials.
> -              aBlock value ]
>                ensure: [ AuthorInitials := originalAuthorInitials ]
>        !
>
> Item was changed:
>  ----- Method: Utilities class>>useAuthorName:during: (in category 'identification') -----
>  useAuthorName: temporaryAuthorName during: aBlock
>
>        | originalAuthorName |
>        originalAuthorName := AuthorName.
> +      [ AuthorName := temporaryAuthorName.
> +      ^ aBlock value ]
> -      [
> -              AuthorName := temporaryAuthorName.
> -              aBlock value ]
>                ensure: [ AuthorName := originalAuthorName ]
>        !



Carpe Squeak!