-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
Add padStart/padEnd methods. Refactor string copy, compare and repeat #171
Add padStart/padEnd methods. Refactor string copy, compare and repeat #171
Conversation
This reverts commit 2e17772.
std/assembly/string.ts
Outdated
var padLen = padString.length; | ||
if (targetLength < length || !padLen) return this; | ||
var len = targetLength - length; | ||
if (len > padLen) padString = padString.repeat(len / padLen + 1); |
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.
if len = 4, padLen = 2
, this would repeat the string 4 / 2 + 1 = 3
times (I'd expect 2 times) - is that correct?
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.
Yes. I can improve this for case, when reminder is zero after division
std/assembly/string.ts
Outdated
memory.copy( | ||
changetype<usize>(out) + HEADER_SIZE + (<usize>length << 1), | ||
changetype<usize>(padString) + HEADER_SIZE, | ||
<usize>targetLength << 1 |
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.
Does this copy out of bounds? Rather <usize>len << 1
?
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.
Fixed!
std/assembly/string.ts
Outdated
changetype<usize>(out), | ||
changetype<usize>(padString), | ||
padLen, | ||
(len + padLen - 1) / padLen |
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.
Need replace to len/padLen
+ rest copy
std/assembly/internal/string.ts
Outdated
destOffset: usize, | ||
src: String, | ||
length: i32, | ||
count: i32 |
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.
What are length
and count
? Can't one be computed from the other?
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.
length
is length of repeated source. Is better rename it to srcLenght
?
EDIT. Yep can remove length
after refactoring. Not needed anymore
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.
count
is how many repeat times we want
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.
Done!
Thank you! :) |
No description provided.