Skip to content

Commit 8444fb9

Browse files
committed
fix(resp):优化整数解析逻辑
- 修改字节到数字的转换方式,使用位运算替代字符减法 - 提高数字解析效率,减少不必要的类型转换 -保持解析逻辑的一致性,确保数据正确性
1 parent 05847ab commit 8444fb9

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/main/java/tech/smartboot/redisun/resp/Integers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static Integers of(ByteBuffer readBuffer) {
5454
byte b = readBuffer.get(readBuffer.position());
5555
if (b >= '0' && b <= '9') {
5656
readBuffer.position(readBuffer.position() + 3);
57-
return ZERO_TO_NINES[b - '0'];
57+
return ZERO_TO_NINES[b & 0x0F];
5858
}
5959
}
6060
return new Integers();

src/main/java/tech/smartboot/redisun/resp/RESP.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected int readInt(ByteBuffer readBuffer) {
111111
while (readBuffer.hasRemaining()) {
112112
byte b = readBuffer.get();
113113
if (b >= '0' && b <= '9') {
114-
v = v * 10 + b - '0';
114+
v = v * 10 + (b & 0x0f);
115115
continue;
116116
} else if (readBuffer.remaining() < 1) {//非完整包,正常退出
117117
readBuffer.reset();

0 commit comments

Comments
 (0)