Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ddc5cd

Browse filesBrowse files
JonasBaaduh95
authored andcommitted
src: cache urlpattern properties
PR-URL: #57465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 176d951 commit 3ddc5cd
Copy full SHA for 3ddc5cd

File tree

Expand file treeCollapse file tree

2 files changed

+22
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-5
lines changed
Open diff view settings
Collapse file

‎src/node_url_pattern.cc‎

Copy file name to clipboardExpand all lines: src/node_url_pattern.cc
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ URLPattern::URLPattern(Environment* env,
168168

169169
void URLPattern::MemoryInfo(MemoryTracker* tracker) const {
170170
tracker->TraitTrackInline(url_pattern_, "url_pattern");
171+
#define URL_PATTERN_CACHED_VALUES(_, lowercase) \
172+
tracker->TrackField(#lowercase, lowercase);
173+
URL_PATTERN_COMPONENTS(URL_PATTERN_CACHED_VALUES)
174+
#undef URL_PATTERN_CACHED_VALUES
171175
}
172176

173177
void URLPattern::New(const FunctionCallbackInfo<Value>& args) {
@@ -466,10 +470,20 @@ URLPattern::URLPatternOptions::FromJsObject(Environment* env,
466470
return options;
467471
}
468472

473+
// Perform value lookup and cache the result in a v8::Global.
469474
#define URL_PATTERN_COMPONENT_GETTERS(uppercase_name, lowercase_name) \
470-
MaybeLocal<Value> URLPattern::uppercase_name() const { \
471-
auto context = env()->context(); \
472-
return ToV8Value(context, url_pattern_.get_##lowercase_name()); \
475+
MaybeLocal<Value> URLPattern::uppercase_name() { \
476+
auto isolate = env()->isolate(); \
477+
if (lowercase_name.IsEmpty()) { \
478+
Local<Value> value; \
479+
if (ToV8Value(env()->context(), url_pattern_.get_##lowercase_name()) \
480+
.ToLocal(&value)) { \
481+
lowercase_name.Reset(isolate, value); \
482+
return value; \
483+
} \
484+
return {}; \
485+
} \
486+
return lowercase_name.Get(isolate); \
473487
}
474488
URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
475489
#undef URL_PATTERN_COMPONENT_GETTERS
Collapse file

‎src/node_url_pattern.h‎

Copy file name to clipboardExpand all lines: src/node_url_pattern.h
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ class URLPattern : public BaseObject {
9393
private:
9494
ada::url_pattern<URLPatternRegexProvider> url_pattern_;
9595
// Getter methods
96-
#define URL_PATTERN_COMPONENT_GETTERS(name, _) \
97-
v8::MaybeLocal<v8::Value> name() const;
96+
#define URL_PATTERN_COMPONENT_GETTERS(name, _) v8::MaybeLocal<v8::Value> name();
9897
URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
9998
#undef URL_PATTERN_COMPONENT_GETTERS
10099
bool HasRegExpGroups() const;
@@ -107,6 +106,10 @@ class URLPattern : public BaseObject {
107106
Environment* env,
108107
const ada::url_pattern_input& input,
109108
std::optional<std::string_view>& baseURL); // NOLINT (runtime/references)
109+
110+
#define URL_PATTERN_CACHED_VALUES(_, name) v8::Global<v8::Value> name;
111+
URL_PATTERN_COMPONENTS(URL_PATTERN_CACHED_VALUES)
112+
#undef URL_PATTERN_CACHED_VALUES
110113
};
111114

112115
} // namespace node::url_pattern

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.