Skip to content
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

Re-using BytesStart byte vector #148

Closed
jonhoo opened this issue Feb 8, 2019 · 0 comments
Closed

Re-using BytesStart byte vector #148

jonhoo opened this issue Feb 8, 2019 · 0 comments

Comments

@jonhoo
Copy link

jonhoo commented Feb 8, 2019

Currently, BytesStart will allocate a Vec<u8> the first time you push additional attributes for the element. That's unfortunate if you're emitting lots of BytesStart in a tight loop. It would be better if it was possible to re-use a BytesStart (specifically its internal Cow::Owned) across iterations. I think all that'd be needed would be two methods: set_name and clear_attributes:

impl BytesStart {
    fn set_name(&mut self, name: &[u8]) {
        let bytes = self.buf.to_mut();
        bytes.clear();
        bytes.extend(name);
        self.name_len = name.len();
    }

    fn clear_attributes(&mut self) {
        self.buf.to_mut().truncate(self.name_len);
    }
}
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

No branches or pull requests

2 participants