| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 53684e4 commit 9ca31cd
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,9 @@ struct ToStringHelper { | |||
| 26 | 26 | return value != nullptr ? value : "(null)"; | |
| 27 | 27 | } | |
| 28 | 28 | static std::string Convert(const std::string& value) { return value; } | |
| 29 | + static std::string Convert(std::string_view value) { | ||
| 30 | + return std::string(value); | ||
| 31 | + } | ||
| 29 | 32 | static std::string Convert(bool value) { return value ? "true" : "false"; } | |
| 30 | 33 | template <unsigned BASE_BITS, | |
| 31 | 34 | typename T, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1280,11 +1280,11 @@ SnapshotableObject::SnapshotableObject(Environment* env, | |||
| 1280 | 1280 | : BaseObject(env, wrap), type_(type) { | |
| 1281 | 1281 | } | |
| 1282 | 1282 | ||
| 1283 | - const char* SnapshotableObject::GetTypeNameChars() const { | ||
| 1283 | + std::string_view SnapshotableObject::GetTypeName() const { | ||
| 1284 | 1284 | switch (type_) { | |
| 1285 | 1285 | #define V(PropertyName, NativeTypeName) \ | |
| 1286 | 1286 | case EmbedderObjectType::k_##PropertyName: { \ | |
| 1287 | - return NativeTypeName::type_name.c_str(); \ | ||
| 1287 | + return NativeTypeName::type_name.as_string_view(); \ | ||
| 1288 | 1288 | } | |
| 1289 | 1289 | SERIALIZABLE_OBJECT_TYPES(V) | |
| 1290 | 1290 | #undef V | |
@@ -1325,7 +1325,7 @@ void DeserializeNodeInternalFields(Local<Object> holder, | |||
| 1325 | 1325 | per_process::Debug(DebugCategory::MKSNAPSHOT, \ | |
| 1326 | 1326 | "Object %p is %s\n", \ | |
| 1327 | 1327 | (*holder), \ | |
| 1328 | - NativeTypeName::type_name.c_str()); \ | ||
| 1328 | + NativeTypeName::type_name.as_string_view()); \ | ||
| 1329 | 1329 | env_ptr->EnqueueDeserializeRequest( \ | |
| 1330 | 1330 | NativeTypeName::Deserialize, \ | |
| 1331 | 1331 | holder, \ | |
@@ -1387,7 +1387,7 @@ StartupData SerializeNodeContextInternalFields(Local<Object> holder, | |||
| 1387 | 1387 | per_process::Debug(DebugCategory::MKSNAPSHOT, | |
| 1388 | 1388 | "Object %p is %s, ", | |
| 1389 | 1389 | *holder, | |
| 1390 | - obj->GetTypeNameChars()); | ||
| 1390 | + obj->GetTypeName()); | ||
| 1391 | 1391 | InternalFieldInfoBase* info = obj->Serialize(index); | |
| 1392 | 1392 | ||
| 1393 | 1393 | per_process::Debug(DebugCategory::MKSNAPSHOT, | |
@@ -1412,7 +1412,7 @@ void SerializeSnapshotableObjects(Realm* realm, | |||
| 1412 | 1412 | } | |
| 1413 | 1413 | SnapshotableObject* ptr = static_cast<SnapshotableObject*>(obj); | |
| 1414 | 1414 | ||
| 1415 | - const char* type_name = ptr->GetTypeNameChars(); | ||
| 1415 | + std::string type_name{ptr->GetTypeName()}; | ||
| 1416 | 1416 | per_process::Debug(DebugCategory::MKSNAPSHOT, | |
| 1417 | 1417 | "Serialize snapshotable object %i (%p), " | |
| 1418 | 1418 | "object=%p, type=%s\n", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,7 +101,7 @@ class SnapshotableObject : public BaseObject { | |||
| 101 | 101 | SnapshotableObject(Environment* env, | |
| 102 | 102 | v8::Local<v8::Object> wrap, | |
| 103 | 103 | EmbedderObjectType type); | |
| 104 | - const char* GetTypeNameChars() const; | ||
| 104 | + std::string_view GetTypeName() const; | ||
| 105 | 105 | ||
| 106 | 106 | // If returns false, the object will not be serialized. | |
| 107 | 107 | virtual bool PrepareForSerialization(v8::Local<v8::Context> context, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -574,11 +574,11 @@ inline bool IsSafeJsInt(v8::Local<v8::Value> v) { | |||
| 574 | 574 | return false; | |
| 575 | 575 | } | |
| 576 | 576 | ||
| 577 | - constexpr size_t FastStringKey::HashImpl(const char* str) { | ||
| 577 | + constexpr size_t FastStringKey::HashImpl(std::string_view str) { | ||
| 578 | 578 | // Low-quality hash (djb2), but just fine for current use cases. | |
| 579 | 579 | size_t h = 5381; | |
| 580 | - while (*str != '\0') { | ||
| 581 | - h = h * 33 + *(str++); // NOLINT(readability/pointer_notation) | ||
| 580 | + for (const char c : str) { | ||
| 581 | + h = h * 33 + c; | ||
| 582 | 582 | } | |
| 583 | 583 | return h; | |
| 584 | 584 | } | |
@@ -589,19 +589,13 @@ constexpr size_t FastStringKey::Hash::operator()( | |||
| 589 | 589 | } | |
| 590 | 590 | ||
| 591 | 591 | constexpr bool FastStringKey::operator==(const FastStringKey& other) const { | |
| 592 | - const char* p1 = name_; | ||
| 593 | - const char* p2 = other.name_; | ||
| 594 | - if (p1 == p2) return true; | ||
| 595 | - do { | ||
| 596 | - if (*(p1++) != *(p2++)) return false; | ||
| 597 | - } while (*p1 != '\0'); | ||
| 598 | - return *p2 == '\0'; | ||
| 592 | + return name_ == other.name_; | ||
| 599 | 593 | } | |
| 600 | 594 | ||
| 601 | - constexpr FastStringKey::FastStringKey(const char* name) | ||
| 602 | - : name_(name), cached_hash_(HashImpl(name)) {} | ||
| 595 | + constexpr FastStringKey::FastStringKey(std::string_view name) | ||
| 596 | + : name_(name), cached_hash_(HashImpl(name)) {} | ||
| 603 | 597 | ||
| 604 | - constexpr const char* FastStringKey::c_str() const { | ||
| 598 | + constexpr std::string_view FastStringKey::as_string_view() const { | ||
| 605 | 599 | return name_; | |
| 606 | 600 | } | |
| 607 | 601 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -837,20 +837,20 @@ class PersistentToLocal { | |||
| 837 | 837 | // computations. | |
| 838 | 838 | class FastStringKey { | |
| 839 | 839 | public: | |
| 840 | - constexpr explicit FastStringKey(const char* name); | ||
| 840 | + constexpr explicit FastStringKey(std::string_view name); | ||
| 841 | 841 | ||
| 842 | 842 | struct Hash { | |
| 843 | 843 | constexpr size_t operator()(const FastStringKey& key) const; | |
| 844 | 844 | }; | |
| 845 | 845 | constexpr bool operator==(const FastStringKey& other) const; | |
| 846 | 846 | ||
| 847 | - constexpr const char* c_str() const; | ||
| 847 | + constexpr std::string_view as_string_view() const; | ||
| 848 | 848 | ||
| 849 | 849 | private: | |
| 850 | - static constexpr size_t HashImpl(const char* str); | ||
| 850 | + static constexpr size_t HashImpl(std::string_view str); | ||
| 851 | 851 | ||
| 852 | - const char* name_; | ||
| 853 | - size_t cached_hash_; | ||
| 852 | + const std::string_view name_; | ||
| 853 | + const size_t cached_hash_; | ||
| 854 | 854 | }; | |
| 855 | 855 | ||
| 856 | 856 | // Like std::static_pointer_cast but for unique_ptr with the default deleter. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments