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: use find instead of char-by-char in FromFilePath() · nodejs/node@9346f15

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_url.cc
    • node_url.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_url.cc‎

Copy file name to clipboardExpand all lines: src/node_url.cc
+14-5Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,21 @@ void BindingData::RegisterExternalReferences(
417417
}
418418
}
419419

420-
std::string FromFilePath(const std::string_view file_path) {
421-
std::string escaped_file_path;
422-
for (size_t i = 0; i < file_path.length(); ++i) {
423-
escaped_file_path += file_path[i];
424-
if (file_path[i] == '%') escaped_file_path += "25";
420+
std::string FromFilePath(std::string_view file_path) {
421+
// Avoid unnecessary allocations.
422+
size_t pos = file_path.empty() ? std::string_view::npos : file_path.find('%');
423+
if (pos == std::string_view::npos) {
424+
return ada::href_from_file(file_path);
425425
}
426+
// Escape '%' characters to a temporary string.
427+
std::string escaped_file_path;
428+
do {
429+
escaped_file_path += file_path.substr(0, pos + 1);
430+
escaped_file_path += "25";
431+
file_path = file_path.substr(pos + 1);
432+
pos = file_path.empty() ? std::string_view::npos : file_path.find('%');
433+
} while (pos != std::string_view::npos);
434+
escaped_file_path += file_path;
426435
return ada::href_from_file(escaped_file_path);
427436
}
428437

Collapse file

‎src/node_url.h‎

Copy file name to clipboardExpand all lines: src/node_url.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class BindingData : public SnapshotableObject {
8181
std::optional<std::string> base);
8282
};
8383

84-
std::string FromFilePath(const std::string_view file_path);
84+
std::string FromFilePath(std::string_view file_path);
8585

8686
} // namespace url
8787

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.