RE: Block evaluation with n+1 arguments

Steffen Märcker <[email protected]> Tue, 11 Apr 2023 15:57:37 +0000
Newsgroups gmane.comp.lang.smalltalk.vwnc
Message-ID <[email protected]>
Hi Steven,

I missed that this is suboptimal when writing this code for illustration. Thanks for pointing it out!

Kind regards,
Steffen


Steven Kelly schrieb am Dienstag, 11. April 2023 11:44:11 (+02:00):

> Steffen Märcker wrote Thursday, April 6, 2023 4:29 PM UTC+3:
> > I want to evaluate a block an argument 'arg1' and additional n arguments
> > given in an array 'args'. The following code does the trick:
> > 
> >     block valueWithArguments: (Array with: arg1) , args.
> > 
> > Is there a way to do this without the overhead of creating a new Array?
> 
> You're actually creating two new Arrays there, first explicitly via #with: and then implicitly via #,
> If you really need to avoid time or memory overhead, this is about twice as fast:
> a := Array new: (newSize := args size + 1).
> a at: 1 put: arg1.
> a replaceFrom: 2 to: newSize with: args startingAt: 1.
> 
> A version with streams is no faster than the original:
> (a := Array new: args size + 1) writeStream nextPut: arg1; nextPutAll: args.
> 
> In recent VW 9.x versions you can simply write {arg1}, args — but that's slower than the original.
> 
> Steve
> 

-- 
Gesendet mit Vivaldi Mail. Laden Sie Vivaldi kostenlos von vivaldi.com herunter.