Re: push to array without copyingby BrowserUk (Pope)
|on Nov 14, 2016 at 23:34 UTC||Need Help??|
The down-side of using references is that dereferencing stuff in multiple places can a) get messy; b) actually end up costing more time than simply duplicating the data and avoiding the dereferencing, if the data items are small.
The hash won't be used once the array is created, so I'm not concerned about the hash values being modified when the array values are.
That observation if key here. If you don't need the values in the hash after you've copied them to the array, don't copy them, move them.
This results in the key 'a' being removed from the hash, and its former value 'test' being transfered directly to $arr without any copying.
I assume that would be faster?
It will be; provided: a) the size of the values is sufficient to make a noticeable difference -- a few hundred bytes would do it -- and b) it doesn't force you to do too much extra work other places as a result.
delete also works with hash slices, which makes this very convenient and efficient for doing multiple transfers simultaneously:
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.