Skip to content

Conversation

@fengmk2
Copy link
Member

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 

@mention-bot
Copy link

@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;
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@pmq20 看看这个代码简化的代码,是否逻辑一直。

Copy link
Contributor

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 是逻辑一致的。

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

那就是 @pmq20 这样改没问题了?

Copy link
Contributor

@pmq20pmq20 left a 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;
Copy link
Contributor

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 是逻辑一致的。

@pmq20
Copy link
Contributor

pmq20 commented Aug 4, 2017

然而还要看是否有溢出的情况,我看看 (0xc0 + ((ch >> 6) & 0x1f))(0x80 + (ch & 0x3f)) 的取值范围

@pmq20
Copy link
Contributor

pmq20 commented Aug 4, 2017

ch 的最大值是 65536,因此(0xc0 + ((ch >> 6) & 0x1f)) 和 (0x80 + (ch & 0x3f)) 的最大值分别是 192 和 128,不会超出 4294967296 因此不需要 >>> 32。确实没问题

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 ```
@fengmk2fengmk2force-pushed the better-performance branch from 0911c1b to 7fa2f4cCompareAugust 7, 2017 07:44
@pmq20pmq20 removed their assignment Aug 5, 2022
Sign up for freeto 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

@fengmk2@mention-bot@pmq20