-
-
Notifications
You must be signed in to change notification settings - Fork 672
TypedArray#set #516
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
TypedArray#set #516
Conversation
update master
pull from master
update from master
There are a bunch of instances where tslint does not like the use of Instead, we need to use |
To recap, looks like we'd need
|
Yeah. I also need to add a slowpath check to see if the ArrayBuffer is writing to itself. |
This is now ready for review again. Current problems
|
I vote that we close this pull request and wait for better type support. |
Adding |
Have been thinking about this a bit lately, and I figured that maybe RTTI can be used to implement it. Target properties are known statically const targetAlignLog2 = alignof<T>();
const targetIsFloat = isFloat<T>(); while source properties can be obtained from RTTI: var sourceInfo = __typeinfo(changetype<BLOCK>(source).rtId);
var sourceAlignLog2: usize = 31 - Math.clz32((sourceInfo / TypeinfoFlags.VALUE_ALIGN_0) & 31);
var sourceIsFloat = (sourceInfo & TypeinfoFlags.VALUE_FLOAT) != 0;
var sourceIsManaged = (sourceInfo & TypeinfoFlags.VALUE_MANAGED) != 0; // disallow this That'd then give us all the possible combinations of integers and floating point values, even for normal arrays. Challenge is to statically eliminate as much as possible by checking target first. |
Does that solution account for Uint8ClampedArray? If the target is Uint8ClampedArray we can easily apply a clamp. |
That's a special case, yeah, but it's only relevant when writing values, which is possible to check statically. |
Alright. The way I see it, I can try to implement this again, or someone can take up the responsibility. It's father's day this weekend and I'll be out camping. Since I don't know enough about rtti, it may be best for @MaxGraey or yourself to implement this feature. |
This implementation tries to take heavy advantage of conditional compilation to enable array parameters.
Accomplishes
The test suite passes, and I'm open to optimization. I know that speed is important, but because
Array.isView()
does not compile to a constant, it's hard to take advantage of conditional compilation in this case.Issues:
Currently the only way to determine if the underlying access type of
SourceT
when it is an array, we must actually perform a (un)checked access to grab a concrete variable with the correct typeSourceU
. Without ever referencing it, we must rely onstub instanceof [numbertype]
to validate what the source is, then use theSET_COPY()
inline method to actually move the data.Please feel free to help me fix this right away, because there is a very large demand to get this function working. 👍