You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/05/15 04:36:45 UTC

[GitHub] [dubbo-go-hessian2] zonghaishang commented on a change in pull request #188: Perf decode string

zonghaishang commented on a change in pull request #188:
URL: https://github.com/apache/dubbo-go-hessian2/pull/188#discussion_r425561321



##########
File path: string.go
##########
@@ -343,36 +342,137 @@ func (d *Decoder) decString(flag int32) (string, error) {
 						last = true
 					}
 
-					l, err := d.getStringLength(b)
+					charLen, err = d.getStringLength(b)
 					if err != nil {
 						return s, perrors.WithStack(err)
 					}
-					charTotal += l
-					bs := make([]rune, charTotal)
-					copy(bs, runeData)
-					runeData = bs
 
+					if chunkLen < 0 {
+						chunkLen = 0
+					}
+
+					if charLen < 0 {
+						charLen = 0
+					}
+
+					chunkLen += charLen
+
+					remain, cap := len(bytesBuf)-offset, charLen<<2
+					if remain < cap {
+						grow := len(bytesBuf) + cap
+						bs := make([]byte, grow)
+						copy(bs, bytesBuf)
+						bytesBuf = bs
+					}
 				default:
 					return s, perrors.New("expect string tag")
 				}
 			}
 
-			r, charLen, byteLen, err = decodeUcs4Rune(d.reader)
+			if buffed := d.Buffered(); chunkLen > 0 {
+				nread, err := d.next(bytesBuf[offset : offset+chunkLen])

Review comment:
       不会有问题,chunkLen是char的长度,优化后的版本会检查后续剩余字节。这里只不过优先一次性读取chunkLen字节长度而已。




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org