allow length in CZString
diff --git a/include/json/value.h b/include/json/value.h
index f8fe824..439f05d 100644
--- a/include/json/value.h
+++ b/include/json/value.h
@@ -176,8 +176,16 @@
private:
void swap(CZString& other);
+ struct StringStorage {
+ DuplicationPolicy policy_: 2;
+ unsigned length_: 30; // 1GB max
+ };
+
const char* cstr_;
- ArrayIndex index_;
+ union {
+ ArrayIndex index_;
+ StringStorage storage_;
+ };
};
public:
diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp
index 24f8f6d..05f2c87 100644
--- a/src/lib_json/json_value.cpp
+++ b/src/lib_json/json_value.cpp
@@ -156,26 +156,30 @@
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
-// Notes: index_ indicates if the string was allocated when
+// Notes: policy_ indicates if the string was allocated when
// a string is stored.
+//
+// TODO: Check for length > 1GB, in Reader.
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
: cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
- index_(allocate) {}
+ storage_({allocate, 0})
+{}
Value::CZString::CZString(const CZString& other)
- : cstr_(other.index_ != noDuplication && other.cstr_ != 0
+ : cstr_(other.storage_.policy_ != noDuplication && other.cstr_ != 0
? duplicateStringValue(other.cstr_)
: other.cstr_),
- index_(other.cstr_
- ? static_cast<ArrayIndex>(other.index_ == noDuplication
+ storage_({(other.cstr_
+ ? (other.storage_.policy_ == noDuplication
? noDuplication : duplicate)
- : other.index_) {}
+ : other.storage_.policy_), 0})
+{}
Value::CZString::~CZString() {
- if (cstr_ && index_ == duplicate)
+ if (cstr_ && storage_.policy_ == duplicate)
releaseStringValue(const_cast<char*>(cstr_));
}
@@ -217,7 +221,7 @@
const char* Value::CZString::c_str() const { return cstr_; }
-bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
+bool Value::CZString::isStaticString() const { return storage_.policy_ == noDuplication; }
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////