Skip to content

Add functions pop_char and shift_char to StrBuf #14052

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

Merged
merged 1 commit into from
May 13, 2014

Conversation

dylanbraithwaite
Copy link
Contributor

Added functions pop_char and shift_char to StrBuf along with unit tests, using the same test cases as push_char.


let popped_char = self.as_slice().char_range_at_reverse(len).ch;
unsafe {
self.vec.set_len(len - popped_char.len_utf8_bytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CharRange's next field contains the index that the char starts at. You should just reuse it instead of recalculating the character length.

let char_range = self.as_slice().char_range_at_reverse(len);
unsafe {
    self.vec.set_len(char_range.next);
}
Some(char_range.ch)

@alexcrichton
Copy link
Member

This looks great @dylanbraithwaite, thanks! With a rebase I think this is good to go.

Also, feel free to ping the PR when you update it, sadly github doesn't send out notifications for updated PRs.

…ppropriate unit tests, using the same test case as push_char.

Changed StrBuf.shift_byte() that it no longer reallocates the buffer by just calling Vec.shift();

Added warning to shift_char()'s docs about it having to copy the whole buffer, as per the docs for
Vec.shift().
@dylanbraithwaite
Copy link
Contributor Author

I've squashed the commits and I think I've managed to rebase it against master. I think this is right?

bors added a commit that referenced this pull request May 13, 2014
…lexcrichton

Added functions pop_char and shift_char to StrBuf along with unit tests, using the same test cases as push_char.
@bors bors closed this May 13, 2014
@bors bors merged commit 1ca6b2c into rust-lang:master May 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants