Skip to content

Commit 43500fa

Browse files
author
Jungku Lee
authoredSep 29, 2023
src: move const variable in node_file.h to node_file.cc
PR-URL: #49688 Refs: #48325 Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 4f84a3d commit 43500fa

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed
 

‎src/node_file.cc

+16-7
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:

‎src/node_file.h

-8
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)
Please sign in to comment.