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 43500fa

Browse filesBrowse files
author
Jungku Lee
authored
src: move const variable in node_file.h to node_file.cc
PR-URL: #49688 Refs: #48325 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 4f84a3d commit 43500fa
Copy full SHA for 43500fa

File tree

Expand file treeCollapse file tree

2 files changed

+16
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-15
lines changed
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+16-7Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,11 +3120,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
31203120
return BindingData::FilePathIsFileReturnType::kIsNotFile;
31213121
}
31223122

3123+
namespace {
3124+
3125+
// define the final index of the algorithm resolution
3126+
// when packageConfig.main is defined.
3127+
constexpr uint8_t legacy_main_extensions_with_main_end = 7;
3128+
// define the final index of the algorithm resolution
3129+
// when packageConfig.main is NOT defined
3130+
constexpr uint8_t legacy_main_extensions_package_fallback_end = 10;
31233131
// the possible file extensions that should be tested
31243132
// 0-6: when packageConfig.main is defined
31253133
// 7-9: when packageConfig.main is NOT defined,
31263134
// or when the previous case didn't found the file
3127-
const std::array<std::string, 10> BindingData::legacy_main_extensions = {
3135+
constexpr std::array<std::string_view, 10> legacy_main_extensions = {
31283136
"",
31293137
".js",
31303138
".json",
@@ -3136,6 +3144,8 @@ const std::array<std::string, 10> BindingData::legacy_main_extensions = {
31363144
".json",
31373145
".node"};
31383146

3147+
} // namespace
3148+
31393149
void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31403150
CHECK_GE(args.Length(), 1);
31413151
CHECK(args[0]->IsString());
@@ -3176,9 +3186,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31763186

31773187
FromNamespacedPath(&initial_file_path);
31783188

3179-
for (int i = 0; i < BindingData::legacy_main_extensions_with_main_end;
3180-
i++) {
3181-
file_path = initial_file_path + BindingData::legacy_main_extensions[i];
3189+
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
3190+
file_path = initial_file_path + std::string(legacy_main_extensions[i]);
31823191

31833192
switch (FilePathIsFile(env, file_path)) {
31843193
case BindingData::FilePathIsFileReturnType::kIsFile:
@@ -3211,10 +3220,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32113220

32123221
FromNamespacedPath(&initial_file_path);
32133222

3214-
for (int i = BindingData::legacy_main_extensions_with_main_end;
3215-
i < BindingData::legacy_main_extensions_package_fallback_end;
3223+
for (int i = legacy_main_extensions_with_main_end;
3224+
i < legacy_main_extensions_package_fallback_end;
32163225
i++) {
3217-
file_path = initial_file_path + BindingData::legacy_main_extensions[i];
3226+
file_path = initial_file_path + std::string(legacy_main_extensions[i]);
32183227

32193228
switch (FilePathIsFile(env, file_path)) {
32203229
case BindingData::FilePathIsFileReturnType::kIsFile:
Collapse file

‎src/node_file.h‎

Copy file name to clipboardExpand all lines: src/node_file.h
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ class BindingData : public SnapshotableObject {
102102

103103
static FilePathIsFileReturnType FilePathIsFile(Environment* env,
104104
const std::string& file_path);
105-
106-
static const std::array<std::string, 10> legacy_main_extensions;
107-
// define the final index of the algorithm resolution
108-
// when packageConfig.main is defined.
109-
static const uint8_t legacy_main_extensions_with_main_end = 7;
110-
// define the final index of the algorithm resolution
111-
// when packageConfig.main is NOT defined
112-
static const uint8_t legacy_main_extensions_package_fallback_end = 10;
113105
};
114106

115107
// structure used to store state during a complex operation, e.g., mkdirp.

0 commit comments

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