New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC Tokens::insertSlices #4250
POC Tokens::insertSlices #4250
Conversation
\strlen($foo); | ||
\strlen($foo); | ||
', | ||
'<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, unchanged Tokens
collection is size of 20.
The fixer has to add 3 new tokens to this collection.
original code has to run offsetSet
45 times, as it has to move all tokens from strlen, then middle strlen, then from json_encode - which means that last strlen was moved 3 times!
my proposal has to run offsetSet
only 20 times, as it has to move one token no more than once
Basically, this gives the possibility to reduce O(n) of calling offsetSet
from O(x*y)
to O(x+y)
where x is number of existing tokens and y is number of new tokens to insert
3c972be
to
1cfe4af
Compare
1cfe4af
to
64aba4e
Compare
why I believe this is a good idea? |
f04d9f3
to
a44d974
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the name insertSlices
fitting situation? Quite often (if not most times) we will use this to insert array of tokens. Wouldn't insertMultiple
(or insertMany
) better describe what the function is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality seems good, just some minor points, up to you if you want to fix them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any progress on this?
Before merging check if the tests files can be reduced, I think the issue is not related to the overall length, so all keys/values can be probably changed to single char like 0
(zero) or ''
(empty string).
@julienfalque , @SpacePossum , what do you think about the proposal in this PR? especially do we want to promote new method as new "best practice" or not?
it can, i was just too lazy to modify example provided by original reporter. |
4bb65a1
to
5ad2981
Compare
for me, $tokens->insertAt(15, $tokensCollection)
$tokens->insertAt(10, [$tokenA, $tokenB]);
$tokens->insertAt(5, $tokenC); I'm trying to express that we are inserting different slices to different indexes at single call: $tokens->insertSlices([
5 => $tokenC,
10 => [$tokenA, $tokenB],
15 => $tokensCollection,
]); we can always change the name later, as it's marked as internal |
d1a962b
to
07cf8b0
Compare
ref #4221
cc @kubawerlos , this is what we discussed in priv