Skip to content

Commit ba169be

Browse files
Jungku Leetargos
Jungku Lee
authored andcommitted
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 e66991e commit ba169be

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
@@ -3155,11 +3155,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
31553155
return BindingData::FilePathIsFileReturnType::kIsNotFile;
31563156
}
31573157

3158+
namespace {
3159+
3160+
// define the final index of the algorithm resolution
3161+
// when packageConfig.main is defined.
3162+
constexpr uint8_t legacy_main_extensions_with_main_end = 7;
3163+
// define the final index of the algorithm resolution
3164+
// when packageConfig.main is NOT defined
3165+
constexpr uint8_t legacy_main_extensions_package_fallback_end = 10;
31583166
// the possible file extensions that should be tested
31593167
// 0-6: when packageConfig.main is defined
31603168
// 7-9: when packageConfig.main is NOT defined,
31613169
// or when the previous case didn't found the file
3162-
const std::array<std::string, 10> BindingData::legacy_main_extensions = {
3170+
constexpr std::array<std::string_view, 10> legacy_main_extensions = {
31633171
"",
31643172
".js",
31653173
".json",
@@ -3171,6 +3179,8 @@ const std::array<std::string, 10> BindingData::legacy_main_extensions = {
31713179
".json",
31723180
".node"};
31733181

3182+
} // namespace
3183+
31743184
void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31753185
CHECK_GE(args.Length(), 1);
31763186
CHECK(args[0]->IsString());
@@ -3211,9 +3221,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32113221

32123222
FromNamespacedPath(&initial_file_path);
32133223

3214-
for (int i = 0; i < BindingData::legacy_main_extensions_with_main_end;
3215-
i++) {
3216-
file_path = initial_file_path + BindingData::legacy_main_extensions[i];
3224+
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
3225+
file_path = initial_file_path + std::string(legacy_main_extensions[i]);
32173226

32183227
switch (FilePathIsFile(env, file_path)) {
32193228
case BindingData::FilePathIsFileReturnType::kIsFile:
@@ -3246,10 +3255,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32463255

32473256
FromNamespacedPath(&initial_file_path);
32483257

3249-
for (int i = BindingData::legacy_main_extensions_with_main_end;
3250-
i < BindingData::legacy_main_extensions_package_fallback_end;
3258+
for (int i = legacy_main_extensions_with_main_end;
3259+
i < legacy_main_extensions_package_fallback_end;
32513260
i++) {
3252-
file_path = initial_file_path + BindingData::legacy_main_extensions[i];
3261+
file_path = initial_file_path + std::string(legacy_main_extensions[i]);
32533262

32543263
switch (FilePathIsFile(env, file_path)) {
32553264
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)