Skip to content

Commit

Permalink
src: clean up PackageConfig pseudo-boolean fields
Browse files Browse the repository at this point in the history
PR-URL: #21987
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
addaleax authored and targos committed Aug 6, 2018
1 parent d38ccaa commit 0ca831a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
27 changes: 10 additions & 17 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,15 @@ class Worker;
namespace loader {
class ModuleWrap;

struct Exists {
enum Bool { Yes, No };
};

struct IsValid {
enum Bool { Yes, No };
};

struct HasMain {
enum Bool { Yes, No };
};

struct PackageConfig {
const Exists::Bool exists;
const IsValid::Bool is_valid;
const HasMain::Bool has_main;
const std::string main;
enum class Exists { Yes, No };
enum class IsValid { Yes, No };
enum class HasMain { Yes, No };

Exists exists;
IsValid is_valid;
HasMain has_main;
std::string main;
};
} // namespace loader

Expand Down Expand Up @@ -673,7 +665,8 @@ class Environment {

std::unordered_multimap<int, loader::ModuleWrap*> module_map;

std::unordered_map<std::string, loader::PackageConfig> package_json_cache;
std::unordered_map<std::string, const loader::PackageConfig>
package_json_cache;

inline double* heap_statistics_buffer() const;
inline void set_heap_statistics_buffer(double* pointer);
Expand Down
8 changes: 6 additions & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,12 @@ Maybe<uv_file> CheckFile(const std::string& path,
return Just(fd);
}

using Exists = PackageConfig::Exists;
using IsValid = PackageConfig::IsValid;
using HasMain = PackageConfig::HasMain;

const PackageConfig& GetPackageConfig(Environment* env,
const std::string path) {
const std::string& path) {
auto existing = env->package_json_cache.find(path);
if (existing != env->package_json_cache.end()) {
return existing->second;
Expand Down Expand Up @@ -530,7 +534,7 @@ const PackageConfig& GetPackageConfig(Environment* env,
}

Local<Value> pkg_main;
HasMain::Bool has_main = HasMain::No;
HasMain has_main = HasMain::No;
std::string main_std;
if (pkg_json->Get(env->context(), env->main_string()).ToLocal(&pkg_main)) {
has_main = HasMain::Yes;
Expand Down

0 comments on commit 0ca831a

Please sign in to comment.