Skip to content

Commit 2bd6851

Browse files
committed
farm out arraybuffers.byteEquality to Buffer
1 parent ec7650f commit 2bd6851

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

src/arraybuffers/arraybuffers.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
/// <reference path='../../../third_party/typings/browser.d.ts' />
22

3-
// Byte-wise equality check of array buffers by comparison of each byte's
4-
// value.
5-
export function byteEquality(b1 :ArrayBuffer, b2 :ArrayBuffer)
6-
:boolean {
7-
var a1 = new Uint8Array(b1);
8-
var a2 = new Uint8Array(b2);
9-
if(a1.byteLength !== a2.byteLength) return false;
10-
for(var i:number = 0; i < a1.byteLength; ++i) {
11-
if(a1[i] !== a2[i]) return false;
12-
}
13-
return true;
3+
// Returns true if b1 and b2 have exactly the same bytes.
4+
export function byteEquality(b1: ArrayBuffer, b2: ArrayBuffer): boolean {
5+
// The Buffer instances share memory with their source ArrayBuffers.
6+
return new Buffer(b1).equals(new Buffer(b2));
147
}
158

169
// Concat |ArrayBuffer|s into a single ArrayBuffer. If size is given, then

0 commit comments

Comments
 (0)