File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,9 @@ Buffer.compare = function compare(a, b) {
139
139
! ( b instanceof Buffer ) )
140
140
throw new TypeError ( 'Arguments must be Buffers' ) ;
141
141
142
+ if ( a === b )
143
+ return 0 ;
144
+
142
145
return internal . compare ( a , b ) ;
143
146
} ;
144
147
@@ -268,6 +271,9 @@ Buffer.prototype.equals = function equals(b) {
268
271
if ( ! ( b instanceof Buffer ) )
269
272
throw new TypeError ( 'Argument must be a Buffer' ) ;
270
273
274
+ if ( this === b )
275
+ return true ;
276
+
271
277
return internal . compare ( this , b ) === 0 ;
272
278
} ;
273
279
@@ -289,6 +295,9 @@ Buffer.prototype.compare = function compare(b) {
289
295
if ( ! ( b instanceof Buffer ) )
290
296
throw new TypeError ( 'Argument must be a Buffer' ) ;
291
297
298
+ if ( this === b )
299
+ return 0 ;
300
+
292
301
return internal . compare ( this , b ) ;
293
302
} ;
294
303
Original file line number Diff line number Diff line change @@ -1128,11 +1128,14 @@ assert.equal(b.compare(c), -1);
1128
1128
assert . equal ( c . compare ( d ) , 1 ) ;
1129
1129
assert . equal ( d . compare ( b ) , 1 ) ;
1130
1130
assert . equal ( b . compare ( d ) , - 1 ) ;
1131
+ assert . equal ( b . compare ( b ) , 0 ) ;
1131
1132
1132
1133
assert . equal ( Buffer . compare ( b , c ) , - 1 ) ;
1133
1134
assert . equal ( Buffer . compare ( c , d ) , 1 ) ;
1134
1135
assert . equal ( Buffer . compare ( d , b ) , 1 ) ;
1135
1136
assert . equal ( Buffer . compare ( b , d ) , - 1 ) ;
1137
+ assert . equal ( Buffer . compare ( c , c ) , 0 ) ;
1138
+
1136
1139
1137
1140
assert . throws ( function ( ) {
1138
1141
var b = new Buffer ( 1 ) ;
@@ -1158,6 +1161,7 @@ var e = new Buffer(6).fill('abcdef');
1158
1161
assert . ok ( b . equals ( c ) ) ;
1159
1162
assert . ok ( ! c . equals ( d ) ) ;
1160
1163
assert . ok ( ! d . equals ( e ) ) ;
1164
+ assert . ok ( d . equals ( d ) ) ;
1161
1165
1162
1166
assert . throws ( function ( ) {
1163
1167
var b = new Buffer ( 1 ) ;
You can’t perform that action at this time.
0 commit comments