| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,16 +88,6 @@ Local<String> BuiltinLoader::GetConfigString(Isolate* isolate) { | |||
| 88 | 88 | return config_.ToStringChecked(isolate); | |
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | - std::vector<std::string_view> BuiltinLoader::GetBuiltinIds() const { | ||
| 92 | - std::vector<std::string_view> ids; | ||
| 93 | - auto source = source_.read(); | ||
| 94 | - ids.reserve(source->size()); | ||
| 95 | - for (auto const& x : *source) { | ||
| 96 | - ids.emplace_back(x.first); | ||
| 97 | - } | ||
| 98 | - return ids; | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | 91 | BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const { | |
| 102 | 92 | BuiltinCategories builtin_categories; | |
| 103 | 93 | ||
@@ -515,26 +505,25 @@ bool BuiltinLoader::CompileAllBuiltinsAndCopyCodeCache( | |||
| 515 | 505 | Local<Context> context, | |
| 516 | 506 | const std::vector<std::string>& eager_builtins, | |
| 517 | 507 | std::vector<CodeCacheInfo>* out) { | |
| 518 | - std::vector<std::string_view> ids = GetBuiltinIds(); | ||
| 508 | + auto ids = GetBuiltinIds(); | ||
| 519 | 509 | bool all_succeeded = true; | |
| 520 | - std::string v8_tools_prefix = "internal/deps/v8/tools/"; | ||
| 521 | - std::string primordial_prefix = "internal/per_context/"; | ||
| 522 | - std::string bootstrap_prefix = "internal/bootstrap/"; | ||
| 523 | - std::string main_prefix = "internal/main/"; | ||
| 524 | - to_eager_compile_ = std::unordered_set<std::string>(eager_builtins.begin(), | ||
| 525 | - eager_builtins.end()); | ||
| 510 | + constexpr std::string_view v8_tools_prefix = "internal/deps/v8/tools/"; | ||
| 511 | + constexpr std::string_view primordial_prefix = "internal/per_context/"; | ||
| 512 | + constexpr std::string_view bootstrap_prefix = "internal/bootstrap/"; | ||
| 513 | + constexpr std::string_view main_prefix = "internal/main/"; | ||
| 514 | + to_eager_compile_ = | ||
| 515 | + std::unordered_set(eager_builtins.begin(), eager_builtins.end()); | ||
| 526 | 516 | ||
| 527 | 517 | for (const auto& id : ids) { | |
| 528 | - if (id.compare(0, v8_tools_prefix.size(), v8_tools_prefix) == 0) { | ||
| 518 | + if (id.starts_with(v8_tools_prefix)) { | ||
| 529 | 519 | // No need to generate code cache for v8 scripts. | |
| 530 | 520 | continue; | |
| 531 | 521 | } | |
| 532 | 522 | ||
| 533 | 523 | // Eagerly compile primordials/boostrap/main scripts during code cache | |
| 534 | 524 | // generation. | |
| 535 | - if (id.compare(0, primordial_prefix.size(), primordial_prefix) == 0 || | ||
| 536 | - id.compare(0, bootstrap_prefix.size(), bootstrap_prefix) == 0 || | ||
| 537 | - id.compare(0, main_prefix.size(), main_prefix) == 0) { | ||
| 525 | + if (id.starts_with(primordial_prefix) || id.starts_with(bootstrap_prefix) || | ||
| 526 | + id.starts_with(main_prefix)) { | ||
| 538 | 527 | to_eager_compile_.emplace(id); | |
| 539 | 528 | } | |
| 540 | 529 | ||
@@ -554,8 +543,8 @@ bool BuiltinLoader::CompileAllBuiltinsAndCopyCodeCache( | |||
| 554 | 543 | } | |
| 555 | 544 | ||
| 556 | 545 | RwLock::ScopedReadLock lock(code_cache_->mutex); | |
| 557 | - for (auto const& item : code_cache_->map) { | ||
| 558 | - out->push_back({item.first, item.second}); | ||
| 546 | + for (const auto& [id, data] : code_cache_->map) { | ||
| 547 | + out->push_back({id, data}); | ||
| 559 | 548 | } | |
| 560 | 549 | return all_succeeded; | |
| 561 | 550 | } | |
@@ -564,8 +553,8 @@ void BuiltinLoader::RefreshCodeCache(const std::vector<CodeCacheInfo>& in) { | |||
| 564 | 553 | RwLock::ScopedLock lock(code_cache_->mutex); | |
| 565 | 554 | code_cache_->map.reserve(in.size()); | |
| 566 | 555 | DCHECK(code_cache_->map.empty()); | |
| 567 | - for (auto const& item : in) { | ||
| 568 | - auto result = code_cache_->map.emplace(item.id, item.data); | ||
| 556 | + for (auto const& [id, data] : in) { | ||
| 557 | + auto result = code_cache_->map.emplace(id, data); | ||
| 569 | 558 | USE(result.second); | |
| 570 | 559 | DCHECK(result.second); | |
| 571 | 560 | } | |
@@ -665,7 +654,7 @@ void BuiltinLoader::BuiltinIdsGetter(Local<Name> property, | |||
| 665 | 654 | Environment* env = Environment::GetCurrent(info); | |
| 666 | 655 | Isolate* isolate = env->isolate(); | |
| 667 | 656 | ||
| 668 | - std::vector<std::string_view> ids = env->builtin_loader()->GetBuiltinIds(); | ||
| 657 | + auto ids = env->builtin_loader()->GetBuiltinIds(); | ||
| 669 | 658 | info.GetReturnValue().Set( | |
| 670 | 659 | ToV8Value(isolate->GetCurrentContext(), ids).ToLocalChecked()); | |
| 671 | 660 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ | |||
| 7 | 7 | #include <map> | |
| 8 | 8 | #include <memory> | |
| 9 | 9 | #include <optional> | |
| 10 | + #include <ranges> | ||
| 10 | 11 | #include <string> | |
| 11 | 12 | #include <unordered_set> | |
| 12 | 13 | #include <vector> | |
@@ -126,7 +127,9 @@ class NODE_EXTERN_PRIVATE BuiltinLoader { | |||
| 126 | 127 | ||
| 127 | 128 | void CopySourceAndCodeCacheReferenceFrom(const BuiltinLoader* other); | |
| 128 | 129 | ||
| 129 | - std::vector<std::string_view> GetBuiltinIds() const; | ||
| 130 | + [[nodiscard]] auto GetBuiltinIds() const { | ||
| 131 | + return std::views::keys(*source_.read()); | ||
| 132 | + } | ||
| 130 | 133 | ||
| 131 | 134 | void SetEagerCompile() { should_eager_compile_ = true; } | |
| 132 | 135 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ | |||
| 27 | 27 | #include <cmath> | |
| 28 | 28 | #include <cstring> | |
| 29 | 29 | #include <locale> | |
| 30 | + #include <ranges> | ||
| 30 | 31 | #include <regex> // NOLINT(build/c++11) | |
| 31 | 32 | #include "node_revert.h" | |
| 32 | 33 | #include "util.h" | |
@@ -379,6 +380,25 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context, | |||
| 379 | 380 | return set_js; | |
| 380 | 381 | } | |
| 381 | 382 | ||
| 383 | + template <typename T, std::size_t U> | ||
| 384 | + v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context, | ||
| 385 | + const std::ranges::elements_view<T, U>& vec, | ||
| 386 | + v8::Isolate* isolate) { | ||
| 387 | + if (isolate == nullptr) isolate = context->GetIsolate(); | ||
| 388 | + v8::EscapableHandleScope handle_scope(isolate); | ||
| 389 | + | ||
| 390 | + MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size()); | ||
| 391 | + arr.SetLength(vec.size()); | ||
| 392 | + auto it = vec.begin(); | ||
| 393 | + for (size_t i = 0; i < vec.size(); ++i) { | ||
| 394 | + if (!ToV8Value(context, *it, isolate).ToLocal(&arr[i])) | ||
| 395 | + return v8::MaybeLocal<v8::Value>(); | ||
| 396 | + std::advance(it, 1); | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length())); | ||
| 400 | + } | ||
| 401 | + | ||
| 382 | 402 | template <typename T, typename U> | |
| 383 | 403 | v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context, | |
| 384 | 404 | const std::unordered_map<T, U>& map, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ | |||
| 42 | 42 | #include <limits> | |
| 43 | 43 | #include <memory> | |
| 44 | 44 | #include <optional> | |
| 45 | + #include <ranges> | ||
| 45 | 46 | #include <set> | |
| 46 | 47 | #include <string> | |
| 47 | 48 | #include <string_view> | |
@@ -733,6 +734,12 @@ inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context, | |||
| 733 | 734 | const std::unordered_map<T, U>& map, | |
| 734 | 735 | v8::Isolate* isolate = nullptr); | |
| 735 | 736 | ||
| 737 | + template <typename T, std::size_t U> | ||
| 738 | + inline v8::MaybeLocal<v8::Value> ToV8Value( | ||
| 739 | + v8::Local<v8::Context> context, | ||
| 740 | + const std::ranges::elements_view<T, U>& vec, | ||
| 741 | + v8::Isolate* isolate = nullptr); | ||
| 742 | + | ||
| 736 | 743 | // These macros expects a `Isolate* isolate` and a `Local<Context> context` | |
| 737 | 744 | // to be in the scope. | |
| 738 | 745 | #define READONLY_PROPERTY(obj, name, value) \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments