perf: optimize passing of colors to native

This commit is contained in:
Mikael Sand
2020-01-18 05:01:55 +02:00
parent c12cd1e01a
commit f138c9b1ab
2 changed files with 4 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ const contextStrokeBrush = [4];
export default function extractBrush(color?: Color) {
if (typeof color === 'number') {
if (color >>> 0 === color && color >= 0 && color <= 0xffffffff) {
return [0, integerColor(color)];
return integerColor(color);
}
}
@@ -37,7 +37,7 @@ export default function extractBrush(color?: Color) {
const int32ARGBColor = extractColor(color);
if (typeof int32ARGBColor === 'number') {
return [0, int32ARGBColor];
return int32ARGBColor;
}
console.warn(`"${color}" is not a valid color or brush`);

View File

@@ -1,6 +1,6 @@
import extractBrush from './extractBrush';
import extractOpacity from './extractOpacity';
import { colorNames, integerColor } from './extractColor';
import { colorNames } from './extractColor';
import { FillProps } from './types';
const fillRules: { evenodd: number; nonzero: number } = {
@@ -8,9 +8,7 @@ const fillRules: { evenodd: number; nonzero: number } = {
nonzero: 1,
};
// default fill is black
const black = colorNames.black;
const defaultFill = [0, integerColor(black as number)];
const defaultFill = colorNames.black;
export default function extractFill(
props: FillProps,