8000 Removed unnecessary complexity from readVString/readIString · protobufjs/bytebuffer.js@64f0e87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64f0e87

Browse files
committed
Removed unnecessary complexity from readVString/readIString
1 parent 95849ea commit 64f0e87

11 files changed

+174
-272
lines changed

dist/ByteBufferAB.js

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,33 +1991,16 @@
19911991
if (offset < 0 || offset + 4 > this.buffer.byteLength)
19921992
throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
19931993
}
1994-
var temp = 0,
1995-
start = offset,
1996-
str;
1997-
if (this.littleEndian) {
1998-
temp = this.view[offset+2] << 16;
1999-
temp |= this.view[offset+1] << 8;
2000-
temp |= this.view[offset ];
2001-
temp += this.view[offset+3] << 24 >>> 0;
2002-
} else {
2003-
temp = this.view[offset+1] << 16;
2004-
temp |= this.view[offset+2] << 8;
2005-
temp |= this.view[offset+3];
2006-
temp += this.view[offset ] << 24 >>> 0;
2007-
}
2008-
offset += 4;
2009-
var k = offset + temp,
2010-
sd;
2011-
utfx.decodeUTF8toUTF16(function() {
2012-
return offset < k ? this.view[offset++] : null;
2013-
}.bind(this), sd = stringDestination(), this.noAssert);
2014-
str = sd();
1994+
var start = offset;
1995+
var len = this.readUint32(offset);
1996+
var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4);
1997+
offset += str['length'];
20151998
if (relative) {
20161999
this.offset = offset;
2017-
return str;
2000+
return str['string'];
20182001
} else {
20192002
return {
2020-
'string': str,
2003+
'string': str['string'],
20212004
'length': offset - start
20222005
};
20232006
}
@@ -2271,23 +2254,16 @@
22712254
if (offset < 0 || offset + 1 > this.buffer.byteLength)
22722255
throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
22732256
}
2274-
var temp = this.readVarint32(offset),
2275-
start = offset,
2276-
str;
2277-
offset += temp['length'];
2278-
temp = temp['value'];
2279-
var k = offset + temp,
2280-
sd = stringDestination();
2281-
utfx.decodeUTF8toUTF16(function() {
2282-
return offset < k ? this.view[offset++] : null;
2283-
}.bind(this), sd, this.noAssert);
2284-
str = sd();
2257+
var start = offset;
2258+
var len = this.readVarint32(offset);
2259+
var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']);
2260+
offset += str['length'];
22852261
if (relative) {
22862262
this.offset = offset;
2287-
return str;
2263+
return str['string'];
22882264
} else {
22892265
return {
2290-
'string': str,
2266+
'string': str['string'],
22912267
'length': offset - start
22922268
};
22932269
}

dist/ByteBufferAB.min.js

Lines changed: 78 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ByteBufferAB.min.js.gz

-8 Bytes
Binary file not shown.

dist/ByteBufferAB.min.map

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

dist/ByteBufferAB_DataView.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,23 +1706,16 @@
17061706
if (offset < 0 || offset + 4 > this.buffer.byteLength)
17071707
throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
17081708
}
1709-
var temp = 0,
1710-
start = offset,
1711-
str;
1712-
temp = this.view.getUint32(offset, this.littleEndian);
1713-
offset += 4;
1714-
var k = offset + temp,
1715-
sd;
1716-
utfx.decodeUTF8toUTF16(function() {
1717-
return offset < k ? this.view.getUint8(offset++) : null;
1718-
}.bind(this), sd = stringDestination(), this.noAssert);
1719-
str = sd();
1709+
var start = offset;
1710+
var len = this.readUint32(offset);
1711+
var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4);
1712+
offset += str['length'];
17201713
if (relative) {
17211714
this.offset = offset;
1722-
return str;
1715+
return str['string'];
17231716
} else {
17241717
return {
1725-
'string': str,
1718+
'string': str['string'],
17261719
'length': offset - start
17271720
};
17281721
}
@@ -1976,23 +1969,16 @@
19761969
if (offset < 0 || offset + 1 > this.buffer.byteLength)
19771970
throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
19781971
}
1979-
var temp = this.readVarint32(offset),
1980-
start = offset,
1981-
str;
1982-
offset += temp['length'];
1983-
temp = temp['value'];
1984-
var k = offset + temp,
1985-
sd = stringDestination();
1986-
utfx.decodeUTF8toUTF16(function() {
1987-
return offset < k ? this.view.getUint8(offset++) : null;
1988-
}.bind(this), sd, this.noAssert);
1989-
str = sd();
1972+
var start = offset;
1973+
var len = this.readVarint32(offset);
1974+
var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']);
1975+
offset += str['length'];
19901976
if (relative) {
19911977
this.offset = offset;
1992-
return str;
1978+
return str['string'];
19931979
} else {
19941980
return {
1995-
'string': str,
1981+
'string': str['string'],
19961982
'length': offset - start
19971983
};
19981984
}

0 commit comments

Comments
 (0)
0