Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataview comparison ignores offsets #53

Open
demurgos opened this issue Mar 12, 2018 · 2 comments
Open

Dataview comparison ignores offsets #53

demurgos opened this issue Mar 12, 2018 · 2 comments

Comments

@demurgos
Copy link

demurgos commented Mar 12, 2018

The dataview comparison in ExtensiveDeepEqualByType compares the underlying buffers instead of comparing the dataviews themselves.
This means that the following dataviews are treated as different even if they represent the same data:

const shortBuffer = new Uint8Array([0x01, 0x01]);
const longBuffer = new Uint8Array([0x00, 0x01, 0x02, 0x03]);
const view1 = new DataView(shortBuffer, 0, 1);
const view2 = new DataView(longBuffer, 1, 1);

Both views represent the slice [0x01] but the equality test returns false because the underlying buffers are different.
Note that this behavior is not even fully consistent. If you want to treat buffer as a public property that should match in both cases, then the offset should also matter. At the moment new DataView(longBuffer, 0, 2) is equal to new DataView(2, 2) because the buffers are the same (even if the data is different due to the different offsets).

@keithamus
Copy link
Member

Seems like this would be useful. How do you propose we make this change? We could .slice() the ArrayBuffers by the respective byteOffset and byteLength and compare the slices values?

@demurgos
Copy link
Author

Yes, I think that comparing the corresponding slices is the expected behavior in the case of deep equality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants