You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By limiting property getting/setting to only where they are
absolutely necessary, we can achieve greater performance
especially with small utf8 inputs and any size base64 inputs.
PR-URL: #1209
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Nicu Micleușanu <[email protected]>
Reviewed-By: Chris Dickinson <[email protected]>
// determine how many bytes we have to check at the end of this buffer
134
-
vari=(buffer.length>=3) ? 3 : buffer.length;
155
+
vari=(buflen>=3) ? 3 : buflen;
156
+
varnewlen=false;
135
157
136
158
// Figure out if one of the last i bytes of our buffer announces an
137
159
// incomplete char.
138
160
for(;i>0;i--){
139
-
varc=buffer[buffer.length-i];
161
+
varc=buffer[buflen-i];
140
162
141
163
// See http://en.wikipedia.org/wiki/UTF-8#Description
142
164
143
165
// 110XXXXX
144
-
if(i==1&&c>>5==0x06){
166
+
if(i===1&&c>>5===0x06){
145
167
this.charLength=2;
168
+
newlen=true;
146
169
break;
147
170
}
148
171
149
172
// 1110XXXX
150
-
if(i<=2&&c>>4==0x0E){
173
+
if(i<=2&&c>>4===0x0E){
151
174
this.charLength=3;
175
+
newlen=true;
152
176
break;
153
177
}
154
178
155
179
// 11110XXX
156
-
if(i<=3&&c>>3==0x1E){
180
+
if(i<=3&&c>>3===0x1E){
157
181
this.charLength=4;
182
+
newlen=true;
158
183
break;
159
184
}
160
185
}
186
+
161
187
this.charReceived=i;
188
+
189
+
returnnewlen;
162
190
};
163
191
164
192
StringDecoder.prototype.end=function(buffer){
165
193
varres='';
166
194
if(buffer&&buffer.length)
167
195
res=this.write(buffer);
168
196
169
-
if(this.charReceived){
170
-
varcr=this.charReceived;
197
+
varcharReceived=this.charReceived;
198
+
if(charReceived){
199
+
varcr=charReceived;
171
200
varbuf=this.charBuffer;
172
201
varenc=this.encoding;
173
-
res+=buf.slice(0,cr).toString(enc);
202
+
res+=buf.toString(enc,0,cr);
174
203
}
175
204
176
205
returnres;
@@ -181,11 +210,13 @@ function passThroughWrite(buffer) {
0 commit comments