Comments (5)
Summary: The TypedDataList
class does not override the operator ==
method, forcing users to rely on a separate equals
method for comparisons. This leads to potential inconsistencies and silent failures if users inadvertently use ==
instead of equals
. The user suggests overriding ==
to perform list comparison for consistency.
from sdk.
Plain Dart List
s also do not override Object.==
. It's a design choice to not have ==
on mutable objects, because being equal by content may be a fleeting property that can change at any time.
Also, it requires having a non-trivial hashCode
that agrees with it.
It's unclear whether Uint8List.fromList([1, 2])
should equals Uint32List.fromList([1, 2])
.
They are lists with the same length and equal elements, but they are also clearly different in very significant ways.
How about Float32List.fromList([1.0, 2.0])
which also contains elements that are equal with the other two?
If we have that kind of equality, then it's not going to be efficient. It won't be using memcmp
on any typed-data lists that have different number types.
Being very efficient would be a reason to have special equality, but if it's only for two Uint8List
s, meaning that the equality will have to compare the types first to see if it can use the efficient branch, then there is little point. (And that would still not work for a Float32List
or Float64List
that contains NaN values, which should not be compared as bits).
I don't see us changing this design at the current time.
If we did it for typed-data lists, why not for normal lists (which is definitely going to be list length + element equality), but then type-data lists are List
s, so they should have the same inefficient equality.
And doing something more efficient for typed-data lists could block adding equality to plain List
s. (If we wanted to.)
I'll recommend just using ListEquality
from package:collection
.
from sdk.
Thanks for the detailed response. I had noticed other issues being raised about the possibility of const
typed data and wondered how equality would be handled in that scenario. That makes sense that it would need a special case from plain List
- but since some of the typed data are immutable (Float64x2
) it seemed like a good candidate. But I can see how special casing it would be inefficient. If extension types
could override this behavior (and delegate to ListEquality
), that would be preferable, but not being able to override Object
members prevents this. Not being able to override Object
(for extensions), combined with trivial equality
on typed data makes it difficult to implement a 2d vector backed by typed data. Both Offset
(Flutter) and Point
(dart:math) implement comparison.
from sdk.
If two constant Uint8List
values with the same value would likely be canonicalized to the same object instance, at which point ==
would work, since the Object.==
implementation is just => identical(this, other);
.
I would have no problem with Float64x2
having ==
, it's not a list and it's not mutable, it really is a data object.
It probably still wouldn't be able to be done as a memcmp
, since we'd want to consider NaN values not equal to themselves.
from sdk.
Good point about const
, the equality would work there. IMO the way equality works is best now for Uint8List
as length + element equality
could be a performance cliff if the comparison is made implicitly as part of a larger data object. Not being able to override this behavior though is the limiting factor as an application can't decide if that comparison is worthwhile. Float64x2
==
comparison would be great, and it would solve 2d vector, but a Rect
would need to be backed by a Float64List
and wouldn't be able to benefit here - there is Float32x4
but not Float64x4
.
from sdk.
Related Issues (20)
- Fix the nullability of `InvalidType`
- [js interop] interop objects sometimes implement Dart types
- Analyzer thinks private getter in mixin is not referenced, even though it is HOT 1
- Issue: Dart Compile JS Fails to Assign External JS Function HOT 2
- [dart2wasm] RuntimeError: unreachable HOT 5
- [analyzer] Wrong error for an enum with non-final external variable
- [js-interop] Help users using JS maps HOT 3
- Support likely() and unlikely() hints for AOT code optimization HOT 1
- [JS-interop] Extension for JSBigint HOT 9
- Attempting to call a DTD service without a dot in the name results in a bad error
- CTRL + Click `part of 'file.dart';` directive doesn't work without `part` directive HOT 2
- [Dart VM] Cannot set pause_isolates_on_exit at runtime HOT 1
- Obfuscation: A need for serious commitment in dart and flutter HOT 7
- bug: analyzer does not report "inherits multiple members named with incompatible signatures." error but compilation fails. HOT 1
- [CP] [stable] Fix analysis server plugins not receiving setContextRoots (or having wrong roots) HOT 2
- dart/runtime/vm/kernel_binary.h: 435: error: Legacy nullability is not supported. HOT 10
- Flaky ffi test crashes on vm-ffi-qemu-linux-release-riscv64
- [Analyzer] Internal error: Exception while using a AvoidRedundantArgumentValues to visit a FunctionExpressionInvocationImpl HOT 1
- [native assets] Use `AddDllDirectory` on native assets dir(s) to enable dynamic linking HOT 2
- Analyzer does not navigate up in the directory tree looking for closest analysis_options.yaml file HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.