Skip to content

Commit 8ffb6c4

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 0803941 commit 8ffb6c4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1313
* Migrate from librsvg's deprecated `rsvg_handle_get_dimensions()` and `rsvg_handle_render_cairo()` functions to the new `rsvg_handle_get_intrinsic_size_in_pixels()` and `rsvg_handle_render_document()` respectively. (#2229)
1414
* Avoid calling virtual methods in constructors/destructors to avoid bypassing virtual dispatch. (#2229)
1515
* Remove unused private field `backend` in the `Backend` class. (#2229)
16+
* Migrated to N-API (by way of node-addon-api) and removed libuv and v8 dependencies
1617
### Added
1718
* Added string tags to support class detection
1819
### Fixed

src/CanvasRenderingContext2d.cc

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

21402140
if (stringValue.IsJust()) {
2141-
std::string str = stringValue.Unwrap().Utf8Value();
2142-
uint32_t rgba = rgba_from_string(str.c_str(), &ok);
2141+
Napi::String str = stringValue.Unwrap();
2142+
char buf[128] = {0};
2143+
napi_status status = napi_get_value_string_utf8(env, str, buf, sizeof(buf) - 1, nullptr);
2144+
if (status != napi_ok) return;
2145+
uint32_t rgba = rgba_from_string(buf, &ok);
21432146
if (!ok) return;
21442147
state->fillPattern = state->fillGradient = NULL;
21452148
state->fill = rgba_create(rgba);

0 commit comments

Comments
 (0)