GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: cache urlpattern properties · nodejs/node@3ddc5cd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_url_pattern.cc
    • node_url_pattern.h
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.