Commit 292c2c91 authored by Wojciech Mandrysz's avatar Wojciech Mandrysz

JS: Re-added comment, moved surrogates code to the right place

parent 7332ffb1
......@@ -941,7 +941,8 @@ jspb.BinaryDecoder.prototype.readString = function(length) {
codeUnits.push(high, low)
}
}
// String.fromCharCode.apply is faster than manually appending characters on
// Chrome 25+, and generates no additional cons string garbage.
var result = String.fromCharCode.apply(null, codeUnits);
this.cursor_ = cursor;
return result;
......
......@@ -413,6 +413,13 @@ jspb.BinaryEncoder.prototype.writeString = function(value) {
for (var i = 0; i < value.length; i++) {
var c = value.charCodeAt(i);
if (c < 128) {
this.buffer_.push(c);
} else if (c < 2048) {
this.buffer_.push((c >> 6) | 192);
this.buffer_.push((c & 63) | 128);
} else if (c < 65536) {
// Look for surrogates
if (c >= 0xD800 && c <= 0xDBFF && i + 1 < value.length) {
var second = value.charCodeAt(i + 1);
......@@ -421,13 +428,6 @@ jspb.BinaryEncoder.prototype.writeString = function(value) {
c = (c - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
}
}
if (c < 128) {
this.buffer_.push(c);
} else if (c < 2048) {
this.buffer_.push((c >> 6) | 192);
this.buffer_.push((c & 63) | 128);
} else if (c < 65536) {
this.buffer_.push((c >> 12) | 224);
this.buffer_.push(((c >> 6) & 63) | 128);
this.buffer_.push((c & 63) | 128);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment