Skip to content

Commit 5893137

Browse files
author
pluris
committed
src: move const variable in node_file.h to node_file.cc
1 parent e9ff810 commit 5893137

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/node_file.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,11 +2909,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
29092909
return BindingData::FilePathIsFileReturnType::kIsNotFile;
29102910
}
29112911

2912+
namespace {
2913+
2914+
// define the final index of the algorithm resolution
2915+
// when packageConfig.main is defined.
2916+
constexpr uint8_t legacy_main_extensions_with_main_end = 7;
2917+
// define the final index of the algorithm resolution
2918+
// when packageConfig.main is NOT defined
2919+
constexpr uint8_t legacy_main_extensions_package_fallback_end = 10;
29122920
// the possible file extensions that should be tested
29132921
// 0-6: when packageConfig.main is defined
29142922
// 7-9: when packageConfig.main is NOT defined,
29152923
// or when the previous case didn't found the file
2916-
const std::array<std::string, 10> BindingData::legacy_main_extensions = {
2924+
constexpr std::array<std::string_view, 10> legacy_main_extensions = {
29172925
"",
29182926
".js",
29192927
".json",
@@ -2925,6 +2933,8 @@ const std::array<std::string, 10> BindingData::legacy_main_extensions = {
29252933
".json",
29262934
".node"};
29272935

2936+
} // namespace
2937+
29282938
void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29292939
CHECK_GE(args.Length(), 1);
29302940
CHECK(args[0]->IsString());
@@ -2965,9 +2975,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29652975

29662976
FromNamespacedPath(&initial_file_path);
29672977

2968-
for (int i = 0; i < BindingData::legacy_main_extensions_with_main_end;
2969-
i++) {
2970-
file_path = initial_file_path + BindingData::legacy_main_extensions[i];
2978+
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
2979+
file_path = initial_file_path + std::string(legacy_main_extensions[i]);
29712980

29722981
switch (FilePathIsFile(env, file_path)) {
29732982
case BindingData::FilePathIsFileReturnType::kIsFile:
@@ -3000,10 +3009,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
30003009

30013010
FromNamespacedPath(&initial_file_path);
30023011

3003-
for (int i = BindingData::legacy_main_extensions_with_main_end;
3004-
i < BindingData::legacy_main_extensions_package_fallback_end;
3012+
for (int i = legacy_main_extensions_with_main_end;
3013+
i < legacy_main_extensions_package_fallback_end;
30053014
i++) {
3006-
file_path = initial_file_path + BindingData::legacy_main_extensions[i];
3015+
file_path = initial_file_path + std::string(legacy_main_extensions[i]);
30073016

30083017
switch (FilePathIsFile(env, file_path)) {
30093018
case BindingData::FilePathIsFileReturnType::kIsFile:

src/node_file.h

Lines 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)