mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 14:31:28 +00:00
Use faster clamping for Uint8ClampedArray (#422)
This commit is contained in:
@ -15,6 +15,10 @@ import {
|
||||
COMPARATOR
|
||||
} from "./internal/sort";
|
||||
|
||||
function clampToByte(value: i32): i32 {
|
||||
return ~(value >> 31) & (((255 - value) >> 31) | value); // & 255
|
||||
}
|
||||
|
||||
export class Int8Array extends TypedArray<i8> {
|
||||
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
|
||||
|
||||
@ -112,12 +116,12 @@ export class Uint8ClampedArray extends Uint8Array {
|
||||
|
||||
@inline @operator("[]=")
|
||||
protected __set(index: i32, value: i32): void {
|
||||
super.__set(index, max(min(value, 255), 0));
|
||||
super.__set(index, clampToByte(value));
|
||||
}
|
||||
|
||||
@inline @operator("{}=")
|
||||
protected __unchecked_set(index: i32, value: i32): void {
|
||||
super.__unchecked_set(index, max(min(value, 255), 0));
|
||||
super.__unchecked_set(index, clampToByte(value));
|
||||
}
|
||||
|
||||
fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {
|
||||
|
Reference in New Issue
Block a user