Skip to content

add new read_chars method, fix bug in read_char #1470

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 2 commits into from
Jan 9, 2012
Merged

add new read_chars method, fix bug in read_char #1470

merged 2 commits into from
Jan 9, 2012

Conversation

grahame
Copy link
Contributor

@grahame grahame commented Jan 8, 2012

having a read_chars method is convenient and more efficient.

the old read_char method had a bug due to re-use of the 'w' width
variable as a loop counter and so was broken for wide characters,
this patch fixes that.

[ sorry for all the spam, a bit of a newbie to contributing via github ]

having a read_chars method is convenient and more efficient.

the old read_char method had a bug due to re-use of the 'w' width
variable as a loop counter and so was broken for wide characters,
this patch fixes that.
@brson
Copy link
Contributor

brson commented Jan 8, 2012

This appears reasonable. Thanks!

Honestly, I haven't pondered the code in depth (too much bit twiddling), but I would be more confident with some accompanying tests, particularly a regression test for the issue you are fixing. You could add them to stdtest::io, probably using a string_reader.

Beyond that I wonder why chars_from_buf gets so little reuse out of the str::* methods, since there are some there for parsing unicode.

@grahame
Copy link
Contributor Author

grahame commented Jan 9, 2012

The previous read_char method had roughly the same unicode bit fiddling code - I agree that it's odd it's not shared. I can look at tidying that up if you like? Perhaps just get the character width, then pass a vec::slice of bytes to a method in str:: that returns the char.

I'll write some tests - I'll have a go this evening after work.

@brson
Copy link
Contributor

brson commented Jan 9, 2012

Don't feel like you need to factor that out as part of this patch, but it might be worth investigating in the future.

@grahame
Copy link
Contributor Author

grahame commented Jan 9, 2012

Sure. Just to check - should I cancel this pull request and resubmit a new one with the patch and the tests when that work is done? I'm not quite up to speed on this github workflow.

@brson
Copy link
Contributor

brson commented Jan 9, 2012

No need to cancel this pull request. If you just push to the same branch the pull request will update to reflect the new code.

@kud1ing
Copy link

kud1ing commented Jan 9, 2012

Would it make sense to extract the core of chars_from_buf() and call that from read_char() instead of read_chars()?

Maybe this is not a real efficiency-issue, but i have a strange gut feeling about allocating a vector of chars, when one only needs to return one char in read_char() ...

Additionally reformat so that 'make check' passes.
@brson
Copy link
Contributor

brson commented Jan 9, 2012

Thanks for the tests. If you want to extract chars_from_buf to make read_chars more efficient then go for it.

brson added a commit that referenced this pull request Jan 9, 2012
add new read_chars method, fix bug in read_char
@brson brson merged commit fbad020 into rust-lang:master Jan 9, 2012
@brson
Copy link
Contributor

brson commented Jan 9, 2012

@Lenny222 Oops, didn't realize you were providing feedback to grahame, and not grahame himself pondering future improvements. Hope you don't mind that I merged this.

bjorn3 added a commit to bjorn3/rust that referenced this pull request Mar 28, 2024
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.

3 participants