-
Notifications
You must be signed in to change notification settings - Fork 10
refactor: improve CESU-8 encoding coding style #28
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
base: master
Are you sure you want to change the base?
Conversation
|
@fengmk2, thanks for your PR! By analyzing the history of the files in this pull request, we identified @gxcsoccer, @dead-horse and @pmq20 to be potential reviewers. |
| // 0x800: 2048 | ||
| this._bytes[index++] = (0xc0 + ((ch >> 6) & 0x1f)) >>> 32; | ||
| this._bytes[index++] = (0x80 + (ch & 0x3f)) >>> 32; | ||
| // this._bytes[index++] = (0xc0 + ((ch >> 6) & 0x1f)) >>> 32; |
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.
@pmq20 看看这个代码简化的代码,是否逻辑一直。
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.
看上去 (0xc0 + ((ch >> 6) & 0x1f)) 和 (0x80 + (ch & 0x3f)) 的运算符都是正数,所以不会加出负数,因此去掉 >>> 32 是逻辑一致的。
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.
那就是 @pmq20 这样改没问题了?
pmq20
left a comment
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.
看上去 (0xc0 + ((ch >> 6) & 0x1f)) 和 (0x80 + (ch & 0x3f)) 的运算符都是正数,所以不会加出负数,因此去掉 >>> 32 是逻辑一致的。
| // 0x800: 2048 | ||
| this._bytes[index++] = (0xc0 + ((ch >> 6) & 0x1f)) >>> 32; | ||
| this._bytes[index++] = (0x80 + (ch & 0x3f)) >>> 32; | ||
| // this._bytes[index++] = (0xc0 + ((ch >> 6) & 0x1f)) >>> 32; |
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.
看上去 (0xc0 + ((ch >> 6) & 0x1f)) 和 (0x80 + (ch & 0x3f)) 的运算符都是正数,所以不会加出负数,因此去掉 >>> 32 是逻辑一致的。
|
然而还要看是否有溢出的情况,我看看 |
|
ch 的最大值是 65536,因此(0xc0 + ((ch >> 6) & 0x1f)) 和 (0x80 + (ch & 0x3f)) 的最大值分别是 192 和 128,不会超出 4294967296 因此不需要 |
BTW: js CESU-8 encoding is faster then Buffer UTF-8 encoding ``` putRawStringSmallLessThan0x80*10000: 672.642ms putRawStringSmallLessThan0x800*10000: 592.960ms putRawStringSmallBiggerThan0x800*10000: 861.010ms putUTF8RawStringSmallLessThan0x80*10000: 841.638ms putUTF8RawStringSmallLessThan0x800*10000: 958.383ms putUTF8RawStringSmallBiggerThan0x800*10000: 1793.470ms ```
0911c1b to
7fa2f4c
Compare
BTW: js CESU-8 encoding is faster then Buffer UTF-8 encoding