mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
url: const-ify APIs, and pass URL by ref
Fixes warnings by Coverity Scan of inefficiences when passing by value instead of passing by const reference. PR-URL: https://github.com/nodejs/node/pull/15615 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
This commit is contained in:
1 parent
27d8202db5
commit
af6af08482
4 files changed
+12
-12
No files matched your search
+7
-7
@@ -323,7 +323,7 @@ struct file_check {
|
|||||||
bool failed = true;
|
bool failed = true;
|
||||||
uv_file file = -1;
|
uv_file file = -1;
|
||||||
};
|
};
|
||||||
inline const struct file_check check_file(URL search,
|
inline const struct file_check check_file(const URL& search,
|
||||||
bool close = false,
|
bool close = false,
|
||||||
bool allow_dir = false) {
|
bool allow_dir = false) {
|
||||||
struct file_check ret;
|
struct file_check ret;
|
||||||
@@ -349,7 +349,7 @@ inline const struct file_check check_file(URL search,
|
|||||||
if (close) uv_fs_close(nullptr, &fs_req, fd, nullptr);
|
if (close) uv_fs_close(nullptr, &fs_req, fd, nullptr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
URL resolve_extensions(URL search, bool check_exact = true) {
|
URL resolve_extensions(const URL& search, bool check_exact = true) {
|
||||||
if (check_exact) {
|
if (check_exact) {
|
||||||
auto check = check_file(search, true);
|
auto check = check_file(search, true);
|
||||||
if (!check.failed) {
|
if (!check.failed) {
|
||||||
@@ -365,10 +365,10 @@ URL resolve_extensions(URL search, bool check_exact = true) {
|
|||||||
}
|
}
|
||||||
return URL("");
|
return URL("");
|
||||||
}
|
}
|
||||||
inline URL resolve_index(URL search) {
|
inline URL resolve_index(const URL& search) {
|
||||||
return resolve_extensions(URL("index", &search), false);
|
return resolve_extensions(URL("index", &search), false);
|
||||||
}
|
}
|
||||||
URL resolve_main(URL search) {
|
URL resolve_main(const URL& search) {
|
||||||
URL pkg("package.json", &search);
|
URL pkg("package.json", &search);
|
||||||
auto check = check_file(pkg);
|
auto check = check_file(pkg);
|
||||||
if (!check.failed) {
|
if (!check.failed) {
|
||||||
@@ -402,7 +402,7 @@ URL resolve_main(URL search) {
|
|||||||
}
|
}
|
||||||
return URL("");
|
return URL("");
|
||||||
}
|
}
|
||||||
URL resolve_module(std::string specifier, URL* base) {
|
URL resolve_module(std::string specifier, const URL* base) {
|
||||||
URL parent(".", base);
|
URL parent(".", base);
|
||||||
URL dir("");
|
URL dir("");
|
||||||
do {
|
do {
|
||||||
@@ -427,7 +427,7 @@ URL resolve_module(std::string specifier, URL* base) {
|
|||||||
return URL("");
|
return URL("");
|
||||||
}
|
}
|
||||||
|
|
||||||
URL resolve_directory(URL search, bool read_pkg_json) {
|
URL resolve_directory(const URL& search, bool read_pkg_json) {
|
||||||
if (read_pkg_json) {
|
if (read_pkg_json) {
|
||||||
auto main = resolve_main(search);
|
auto main = resolve_main(search);
|
||||||
if (!(main.flags() & URL_FLAGS_FAILED)) return main;
|
if (!(main.flags() & URL_FLAGS_FAILED)) return main;
|
||||||
@@ -438,7 +438,7 @@ URL resolve_directory(URL search, bool read_pkg_json) {
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
URL Resolve(std::string specifier, URL* base, bool read_pkg_json) {
|
URL Resolve(std::string specifier, const URL* base, bool read_pkg_json) {
|
||||||
URL pure_url(specifier);
|
URL pure_url(specifier);
|
||||||
if (!(pure_url.flags() & URL_FLAGS_FAILED)) {
|
if (!(pure_url.flags() & URL_FLAGS_FAILED)) {
|
||||||
return pure_url;
|
return pure_url;
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
namespace node {
|
namespace node {
|
||||||
namespace loader {
|
namespace loader {
|
||||||
|
|
||||||
node::url::URL Resolve(std::string specifier, node::url::URL* base,
|
node::url::URL Resolve(std::string specifier, const node::url::URL* base,
|
||||||
bool read_pkg_json = false);
|
bool read_pkg_json = false);
|
||||||
|
|
||||||
class ModuleWrap : public BaseObject {
|
class ModuleWrap : public BaseObject {
|
||||||
|
|||||||
+2
-2
@@ -2081,7 +2081,7 @@ static void DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
|
|||||||
v8::NewStringType::kNormal).ToLocalChecked());
|
v8::NewStringType::kNormal).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string URL::ToFilePath() {
|
std::string URL::ToFilePath() const {
|
||||||
if (context_.scheme != "file:") {
|
if (context_.scheme != "file:") {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -2102,7 +2102,7 @@ std::string URL::ToFilePath() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
std::string decoded_path;
|
std::string decoded_path;
|
||||||
for (std::string& part : context_.path) {
|
for (const std::string& part : context_.path) {
|
||||||
std::string decoded;
|
std::string decoded;
|
||||||
PercentDecode(part.c_str(), part.length(), &decoded);
|
PercentDecode(part.c_str(), part.length(), &decoded);
|
||||||
for (char& ch : decoded) {
|
for (char& ch : decoded) {
|
||||||
|
|||||||
+2
-2
@@ -154,7 +154,7 @@ class URL {
|
|||||||
return context_.fragment;
|
return context_.fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string path() {
|
std::string path() const {
|
||||||
std::string ret;
|
std::string ret;
|
||||||
for (auto i = context_.path.begin(); i != context_.path.end(); i++) {
|
for (auto i = context_.path.begin(); i != context_.path.end(); i++) {
|
||||||
ret += '/';
|
ret += '/';
|
||||||
@@ -165,7 +165,7 @@ class URL {
|
|||||||
|
|
||||||
// Get the path of the file: URL in a format consumable by native file system
|
// Get the path of the file: URL in a format consumable by native file system
|
||||||
// APIs. Returns an empty string if something went wrong.
|
// APIs. Returns an empty string if something went wrong.
|
||||||
std::string ToFilePath();
|
std::string ToFilePath() const;
|
||||||
|
|
||||||
const Local<Value> ToObject(Environment* env) const;
|
const Local<Value> ToObject(Environment* env) const;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user