Skip to content

Commit

Permalink
optimize fillStyle to be 10% faster
Browse files Browse the repository at this point in the history
this is possibly a hot path, and avoiding the C++ string helps a
little bit
  • Loading branch information
chearon committed Apr 23, 2023
1 parent 0803941 commit 8ffb6c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
* 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)
* Avoid calling virtual methods in constructors/destructors to avoid bypassing virtual dispatch. (#2229)
* Remove unused private field `backend` in the `Backend` class. (#2229)
* Migrated to N-API (by way of node-addon-api) and removed libuv and v8 dependencies
### Added
* Added string tags to support class detection
### Fixed
Expand Down
7 changes: 5 additions & 2 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2138,8 +2138,11 @@ Context2d::_setFillColor(Napi::Value arg) {
short ok;

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

0 comments on commit 8ffb6c4

Please sign in to comment.