Skip to content

Commit 8762e1f

Browse files
committed
Remove unneeded that parameter
Thanks for pointing this out, @jdalton.
1 parent 707c90d commit 8762e1f

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

index.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ function typedArraySupport () {
5151
}
5252
}
5353

54-
function createBuffer (that, length) {
54+
function createBuffer (length) {
5555
if (K_MAX_LENGTH < length) {
5656
throw new RangeError('Invalid typed array length')
5757
}
5858
// Return an augmented `Uint8Array` instance
59-
that = new Uint8Array(length)
60-
that.__proto__ = Buffer.prototype
61-
return that
59+
var buf = new Uint8Array(length)
60+
buf.__proto__ = Buffer.prototype
61+
return buf
6262
}
6363

6464
/**
@@ -79,9 +79,9 @@ function Buffer (arg, encodingOrOffset, length) {
7979
'If encoding is specified then the first argument must be a string'
8080
)
8181
}
82-
return allocUnsafe(this, arg)
82+
return allocUnsafe(arg)
8383
}
84-
return from(this, arg, encodingOrOffset, length)
84+
return from(arg, encodingOrOffset, length)
8585
}
8686

8787
Buffer.prototype.__proto__ = Uint8Array.prototype
@@ -100,20 +100,20 @@ if (typeof Symbol !== 'undefined' && Symbol.species &&
100100

101101
Buffer.poolSize = 8192 // not used by this implementation
102102

103-
function from (that, value, encodingOrOffset, length) {
103+
function from (value, encodingOrOffset, length) {
104104
if (typeof value === 'number') {
105105
throw new TypeError('"value" argument must not be a number')
106106
}
107107

108108
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
109-
return fromArrayBuffer(that, value, encodingOrOffset, length)
109+
return fromArrayBuffer(value, encodingOrOffset, length)
110110
}
111111

112112
if (typeof value === 'string') {
113-
return fromString(that, value, encodingOrOffset)
113+
return fromString(value, encodingOrOffset)
114114
}
115115

116-
return fromObject(that, value)
116+
return fromObject(value)
117117
}
118118

119119
/**
@@ -125,7 +125,7 @@ function from (that, value, encodingOrOffset, length) {
125125
* Buffer.from(arrayBuffer[, byteOffset[, length]])
126126
**/
127127
Buffer.from = function (value, encodingOrOffset, length) {
128-
return from(null, value, encodingOrOffset, length)
128+
return from(value, encodingOrOffset, length)
129129
}
130130

131131
function assertSize (size) {
@@ -136,49 +136,49 @@ function assertSize (size) {
136136
}
137137
}
138138

139-
function alloc (that, size, fill, encoding) {
139+
function alloc (size, fill, encoding) {
140140
assertSize(size)
141141
if (size <= 0) {
142-
return createBuffer(that, size)
142+
return createBuffer(size)
143143
}
144144
if (fill !== undefined) {
145145
// Only pay attention to encoding if it's a string. This
146146
// prevents accidentally sending in a number that would
147147
// be interpretted as a start offset.
148148
return typeof encoding === 'string'
149-
? createBuffer(that, size).fill(fill, encoding)
150-
: createBuffer(that, size).fill(fill)
149+
? createBuffer(size).fill(fill, encoding)
150+
: createBuffer(size).fill(fill)
151151
}
152-
return createBuffer(that, size)
152+
return createBuffer(size)
153153
}
154154

155155
/**
156156
* Creates a new filled Buffer instance.
157157
* alloc(size[, fill[, encoding]])
158158
**/
159159
Buffer.alloc = function (size, fill, encoding) {
160-
return alloc(null, size, fill, encoding)
160+
return alloc(size, fill, encoding)
161161
}
162162

163-
function allocUnsafe (that, size) {
163+
function allocUnsafe (size) {
164164
assertSize(size)
165-
return createBuffer(that, size < 0 ? 0 : checked(size) | 0)
165+
return createBuffer(size < 0 ? 0 : checked(size) | 0)
166166
}
167167

168168
/**
169169
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
170170
* */
171171
Buffer.allocUnsafe = function (size) {
172-
return allocUnsafe(null, size)
172+
return allocUnsafe(size)
173173
}
174174
/**
175175
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
176176
*/
177177
Buffer.allocUnsafeSlow = function (size) {
178-
return allocUnsafe(null, size)
178+
return allocUnsafe(size)
179179
}
180180

181-
function fromString (that, string, encoding) {
181+
function fromString (string, encoding) {
182182
if (typeof encoding !== 'string' || encoding === '') {
183183
encoding = 'utf8'
184184
}
@@ -188,30 +188,30 @@ function fromString (that, string, encoding) {
188188
}
189189

190190
var length = byteLength(string, encoding) | 0
191-
that = createBuffer(that, length)
191+
var buf = createBuffer(length)
192192

193-
var actual = that.write(string, encoding)
193+
var actual = buf.write(string, encoding)
194194

195195
if (actual !== length) {
196196
// Writing a hex string, for example, that contains invalid characters will
197197
// cause everything after the first invalid character to be ignored. (e.g.
198198
// 'abxxcd' will be treated as 'ab')
199-
that = that.slice(0, actual)
199+
buf = buf.slice(0, actual)
200200
}
201201

202-
return that
202+
return buf
203203
}
204204

205-
function fromArrayLike (that, array) {
205+
function fromArrayLike (array) {
206206
var length = array.length < 0 ? 0 : checked(array.length) | 0
207-
that = createBuffer(that, length)
207+
var buf = createBuffer(length)
208208
for (var i = 0; i < length; i += 1) {
209-
that[i] = array[i] & 255
209+
buf[i] = array[i] & 255
210210
}
211-
return that
211+
return buf
212212
}
213213

214-
function fromArrayBuffer (that, array, byteOffset, length) {
214+
function fromArrayBuffer (array, byteOffset, length) {
215215
array.byteLength // this throws if `array` is not a valid ArrayBuffer
216216

217217
if (byteOffset < 0 || array.byteLength < byteOffset) {
@@ -222,44 +222,44 @@ function fromArrayBuffer (that, array, byteOffset, length) {
222222
throw new RangeError('\'length\' is out of bounds')
223223
}
224224

225+
var buf
225226
if (byteOffset === undefined && length === undefined) {
226-
array = new Uint8Array(array)
227+
buf = new Uint8Array(array)
227228
} else if (length === undefined) {
228-
array = new Uint8Array(array, byteOffset)
229+
buf = new Uint8Array(array, byteOffset)
229230
} else {
230-
array = new Uint8Array(array, byteOffset, length)
231+
buf = new Uint8Array(array, byteOffset, length)
231232
}
232233

233-
// Return an augmented `Uint8Array` instance, for best performance
234-
that = array
235-
that.__proto__ = Buffer.prototype
236-
return that
234+
// Return an augmented `Uint8Array` instance
235+
buf.__proto__ = Buffer.prototype
236+
return buf
237237
}
238238

239-
function fromObject (that, obj) {
239+
function fromObject (obj) {
240240
if (Buffer.isBuffer(obj)) {
241241
var len = checked(obj.length) | 0
242-
that = createBuffer(that, len)
242+
var buf = createBuffer(len)
243243

244-
if (that.length === 0) {
245-
return that
244+
if (buf.length === 0) {
245+
return buf
246246
}
247247

248-
obj.copy(that, 0, 0, len)
249-
return that
248+
obj.copy(buf, 0, 0, len)
249+
return buf
250250
}
251251

252252
if (obj) {
253253
if ((typeof ArrayBuffer !== 'undefined' &&
254254
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
255255
if (typeof obj.length !== 'number' || isnan(obj.length)) {
256-
return createBuffer(that, 0)
256+
return createBuffer(0)
257257
}
258-
return fromArrayLike(that, obj)
258+
return fromArrayLike(obj)
259259
}
260260

261261
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
262-
return fromArrayLike(that, obj.data)
262+
return fromArrayLike(obj.data)
263263
}
264264
}
265265

@@ -1030,6 +1030,7 @@ Buffer.prototype.slice = function slice (start, end) {
10301030
if (end < start) end = start
10311031

10321032
var newBuf = this.subarray(start, end)
1033+
// Return an augmented `Uint8Array` instance
10331034
newBuf.__proto__ = Buffer.prototype
10341035
return newBuf
10351036
}

0 commit comments

Comments
 (0)