| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent edbe38d commit 62a0e91
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,47 +59,40 @@ class NonOwningExternalTwoByteResource | |||
| 59 | 59 | class UnionBytes { | |
| 60 | 60 | public: | |
| 61 | 61 | UnionBytes(const uint16_t* data, size_t length) | |
| 62 | - : is_one_byte_(false), two_bytes_(data), length_(length) {} | ||
| 62 | + : one_bytes_(nullptr), two_bytes_(data), length_(length) {} | ||
| 63 | 63 | UnionBytes(const uint8_t* data, size_t length) | |
| 64 | - : is_one_byte_(true), one_bytes_(data), length_(length) {} | ||
| 64 | + : one_bytes_(data), two_bytes_(nullptr), length_(length) {} | ||
| 65 | 65 | ||
| 66 | 66 | UnionBytes(const UnionBytes&) = default; | |
| 67 | 67 | UnionBytes& operator=(const UnionBytes&) = default; | |
| 68 | 68 | UnionBytes(UnionBytes&&) = default; | |
| 69 | 69 | UnionBytes& operator=(UnionBytes&&) = default; | |
| 70 | 70 | ||
| 71 | - bool is_one_byte() const { return is_one_byte_; } | ||
| 71 | + bool is_one_byte() const { return one_bytes_ != nullptr; } | ||
| 72 | 72 | const uint16_t* two_bytes_data() const { | |
| 73 | - CHECK(!is_one_byte_); | ||
| 74 | 73 | CHECK_NOT_NULL(two_bytes_); | |
| 75 | 74 | return two_bytes_; | |
| 76 | 75 | } | |
| 77 | 76 | const uint8_t* one_bytes_data() const { | |
| 78 | - CHECK(is_one_byte_); | ||
| 79 | 77 | CHECK_NOT_NULL(one_bytes_); | |
| 80 | 78 | return one_bytes_; | |
| 81 | 79 | } | |
| 82 | 80 | v8::Local<v8::String> ToStringChecked(v8::Isolate* isolate) const { | |
| 83 | - if (is_one_byte_) { | ||
| 84 | - CHECK_NOT_NULL(one_bytes_); | ||
| 81 | + if (is_one_byte()) { | ||
| 85 | 82 | NonOwningExternalOneByteResource* source = | |
| 86 | - new NonOwningExternalOneByteResource(one_bytes_, length_); | ||
| 83 | + new NonOwningExternalOneByteResource(one_bytes_data(), length_); | ||
| 87 | 84 | return v8::String::NewExternalOneByte(isolate, source).ToLocalChecked(); | |
| 88 | 85 | } else { | |
| 89 | - CHECK_NOT_NULL(two_bytes_); | ||
| 90 | 86 | NonOwningExternalTwoByteResource* source = | |
| 91 | - new NonOwningExternalTwoByteResource(two_bytes_, length_); | ||
| 87 | + new NonOwningExternalTwoByteResource(two_bytes_data(), length_); | ||
| 92 | 88 | return v8::String::NewExternalTwoByte(isolate, source).ToLocalChecked(); | |
| 93 | 89 | } | |
| 94 | 90 | } | |
| 95 | 91 | size_t length() { return length_; } | |
| 96 | 92 | ||
| 97 | 93 | private: | |
| 98 | - bool is_one_byte_; | ||
| 99 | - union { | ||
| 100 | - const uint8_t* one_bytes_; | ||
| 101 | - const uint16_t* two_bytes_; | ||
| 102 | - }; | ||
| 94 | + const uint8_t* one_bytes_; | ||
| 95 | + const uint16_t* two_bytes_; | ||
| 103 | 96 | size_t length_; | |
| 104 | 97 | }; | |
| 105 | 98 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments