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

Encoding: compare with case insensitive UTF-8 to avoid using iconv when not necessary #6355

Conversation

asterite
Copy link
Member

@asterite asterite commented Jul 7, 2018

We have IO#set_encoding which accepts an encoding. If it's UTF-8 there's nothing to do, because IO is assumed to be UTF-8 by default (regarding text). The current comparison is case sensitive, but in some cases the encoding can come with other cases (like in #6353). So to avoid using iconv, which should be slower then just doing it in Crystal (and also a bit redundant), I added a case insensitive comparison.

Update: includes tests.

@asterite asterite force-pushed the feature/dont-use-iconv-for-case-insensitive-utf8 branch 2 times, most recently from 5c29c3d to b215bbc Compare July 7, 2018 21:23
@jhass
Copy link
Member

jhass commented Jul 8, 2018

Do we want to allow utf8 (without the dash) too?

@asterite
Copy link
Member Author

asterite commented Jul 8, 2018

@jhass Maybe, I'll later check if that's valid for iconv.

@RX14
Copy link
Contributor

RX14 commented Jul 8, 2018

I don't think it is - at least it's behind a -DUSE_HPUX_ALIASES compiler flag which is not the default.

@RX14
Copy link
Contributor

RX14 commented Jul 8, 2018

Oh - glibc iconv supports utf8: https://github.com/bminor/glibc/blob/master/iconv/iconv_open.c#L34.

Seems libiconv isn't used and iconv is built into the glibc.

@asterite asterite force-pushed the feature/dont-use-iconv-for-case-insensitive-utf8 branch from b215bbc to c331845 Compare July 8, 2018 13:29
@asterite
Copy link
Member Author

asterite commented Jul 8, 2018

Updated to check against "UTF-8" and "UTF8"

@RX14 RX14 modified the milestones: 0.26.0, Next Jul 8, 2018
@RX14 RX14 merged commit afeaee4 into crystal-lang:master Jul 8, 2018
@RX14 RX14 modified the milestones: Next, 0.26.0 Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants