Skip to content

Commit bafc86f

Browse files
Trottrvagg
authored andcommitted
buffer: refactor redeclared variables
A handful of variable declarations in `lib/buffer.js` redeclare the same variable in the same scope. This change removes each redeclaration by switching to `const`, switching to `let`, or explicitly hoisting the `var` declaration. PR-URL: #4886 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Klauke <[email protected]>
1 parent 89d1149 commit bafc86f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

‎lib/buffer.js‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function fromString(string, encoding){
120120

121121
functionfromObject(obj){
122122
if(objinstanceofBuffer){
123-
varb=allocate(obj.length);
123+
constb=allocate(obj.length);
124124

125125
if(b.length===0)
126126
returnb;
@@ -130,9 +130,9 @@ function fromObject(obj){
130130
}
131131

132132
if(Array.isArray(obj)){
133-
varlength=obj.length;
134-
varb=allocate(length);
135-
for(vari=0;i<length;i++)
133+
constlength=obj.length;
134+
constb=allocate(length);
135+
for(leti=0;i<length;i++)
136136
b[i]=obj[i]&255;
137137
returnb;
138138
}
@@ -146,22 +146,22 @@ function fromObject(obj){
146146
}
147147

148148
if(obj.bufferinstanceofArrayBuffer||obj.length){
149-
varlength;
149+
letlength;
150150
if(typeofobj.length!=='number'||obj.length!==obj.length)
151151
length=0;
152152
else
153153
length=obj.length;
154-
varb=allocate(length);
155-
for(vari=0;i<length;i++){
154+
constb=allocate(length);
155+
for(leti=0;i<length;i++){
156156
b[i]=obj[i]&255;
157157
}
158158
returnb;
159159
}
160160

161161
if(obj.type==='Buffer'&&Array.isArray(obj.data)){
162162
vararray=obj.data;
163-
varb=allocate(array.length);
164-
for(vari=0;i<array.length;i++)
163+
constb=allocate(array.length);
164+
for(leti=0;i<array.length;i++)
165165
b[i]=array[i]&255;
166166
returnb;
167167
}
@@ -226,15 +226,15 @@ Buffer.concat = function(list, length){
226226

227227
if(length===undefined){
228228
length=0;
229-
for(vari=0;i<list.length;i++)
229+
for(leti=0;i<list.length;i++)
230230
length+=list[i].length;
231231
}else{
232232
length=length>>>0;
233233
}
234234

235235
varbuffer=newBuffer(length);
236236
varpos=0;
237-
for(vari=0;i<list.length;i++){
237+
for(leti=0;i<list.length;i++){
238238
varbuf=list[i];
239239
buf.copy(buffer,pos);
240240
pos+=buf.length;
@@ -396,10 +396,11 @@ function slowToString(encoding, start, end){
396396

397397

398398
Buffer.prototype.toString=function(){
399+
letresult;
399400
if(arguments.length===0){
400-
varresult=this.utf8Slice(0,this.length);
401+
result=this.utf8Slice(0,this.length);
401402
}else{
402-
varresult=slowToString.apply(this,arguments);
403+
result=slowToString.apply(this,arguments);
403404
}
404405
if(result===undefined)
405406
thrownewError('toString failed');

0 commit comments

Comments
(0)