Skip to content

Commit 83d8af0

Browse files
committed
optimize fillStyle to be 10% faster
this is possibly a hot path, and avoiding the C++ string helps a little bit
1 parent 42ea2ff commit 83d8af0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/CanvasRenderingContext2d.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -2097,8 +2097,11 @@ Context2d::_setFillColor(Napi::Value arg) {
20972097
short ok;
20982098

20992099
if (stringValue.IsJust()) {
2100-
std::string str = stringValue.Unwrap().Utf8Value();
2101-
uint32_t rgba = rgba_from_string(str.c_str(), &ok);
2100+
Napi::String str = stringValue.Unwrap();
2101+
char buf[128] = {0};
2102+
napi_status status = napi_get_value_string_utf8(env, str, buf, sizeof(buf) - 1, nullptr);
2103+
if (status != napi_ok) return;
2104+
uint32_t rgba = rgba_from_string(buf, &ok);
21022105
if (!ok) return;
21032106
state->fillPattern = state->fillGradient = NULL;
21042107
state->fill = rgba_create(rgba);

0 commit comments

Comments
 (0)