#80 NativeArray: fix moveTo, moveFrom if other array has different type

Closed
opened 4 years ago by ranides · 2 comments
ranides commented 4 years ago

At this moment moveTo/moveFrom assumes that second array has identical type. If second array has different, even assign-compatible type, exception will be thrown because we will try to convert at array level.

It should be implemented in this way, that current implementation runs for identical types, and unoptimized version (which uses get/set) is returned in other cases.

At this moment moveTo/moveFrom assumes that second array has *identical* type. If second array has different, even assign-compatible type, exception will be thrown because we will try to convert at array level. It should be implemented in this way, that current implementation runs for identical types, and unoptimized version (which uses get/set) is returned in other cases.
ranides commented 4 years ago
Owner

The same applies to all comparators

The same applies to all comparators
ranides commented 4 years ago
Owner

comparators use cast at object level:

public IntComparator comparator(NativeArray values) {
    DoubleArray that = (DoubleArray)values;
    return (a,b) -> Double.compare(this.array[a], that.array[b]);
}

it can be transformed to:

public IntComparator comparator(NativeArray values) {
    double[] other = values.$array();
    return (a,b) -> Double.compare(this.array[a], other[b]);
}

That version of optimized operation will avoid accessing field over and over again.

comparators use cast at object level: ``` public IntComparator comparator(NativeArray values) { DoubleArray that = (DoubleArray)values; return (a,b) -> Double.compare(this.array[a], that.array[b]); } ``` it can be transformed to: ``` public IntComparator comparator(NativeArray values) { double[] other = values.$array(); return (a,b) -> Double.compare(this.array[a], other[b]); } ``` That version of optimized operation will avoid accessing field over and over again.
ranides referenced this issue from a commit 3 years ago
Sign in to join this conversation.
No Milestone
No assignee
1 Participants
Loading...
Cancel
Save
There is no content yet.