Skip to content

pack the {type,allocated} bitfield #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def amalgamate_source(source_top_dir=None,
header.add_text("/// to prevent private header inclusion.")
header.add_text("#define JSON_IS_AMALGAMATION")
header.add_file("include/json/version.h")
#header.add_file("include/json/allocator.h") # Not available here.
header.add_file("include/json/allocator.h")
header.add_file("include/json/config.h")
header.add_file("include/json/forwards.h")
header.add_file("include/json/features.h")
Expand Down
29 changes: 16 additions & 13 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,14 @@ Json::Value obj_value(Json::objectValue); // {}
Value(const CppTL::ConstString& value);
#endif
Value(bool value);
/// Deep copy.
Value(const Value& other);
#if JSON_HAS_RVALUE_REFERENCES
/// Move constructor
Value(Value&& other);
#endif
~Value();

/// Deep copy, then swap(other).
/// \note Over-write existing comments. To preserve comments, use
/// \note Overwrite existing comments. To preserve comments, use
/// #swapPayload().
Value& operator=(Value other);
Value& operator=(const Value& other);
Value& operator=(Value&& other);

/// Swap everything.
void swap(Value& other);
Expand Down Expand Up @@ -616,6 +612,10 @@ Json::Value obj_value(Json::objectValue); // {}
ptrdiff_t getOffsetLimit() const;

private:
void setType(ValueType v) { bits_.value_type_ = v; }
bool isAllocated() const { return bits_.allocated_; }
void setIsAllocated(bool v) { bits_.allocated_ = v; }

void initBasic(ValueType type, bool allocated = false);
void dupPayload(const Value& other);
void releasePayload();
Expand Down Expand Up @@ -647,14 +647,17 @@ Json::Value obj_value(Json::objectValue); // {}
LargestUInt uint_;
double real_;
bool bool_;
char* string_; // actually ptr to unsigned, followed by str, unless
// !allocated_
char* string_; // if allocated_, ptr to { unsigned, char[] }.
ObjectValues* map_;
} value_;
ValueType type_ : 8;
unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is
// useless. If not allocated_, string_ must be
// null-terminated.

struct {
// Really a ValueType, but types should agree for bitfield packing.
unsigned int value_type_ : 8;
// Unless allocated_, string_ must be null-terminated.
unsigned int allocated_ : 1;
} bits_;

CommentInfo* comments_;

// [start, limit) byte offsets in the source JSON text from which this Value
Expand Down
Loading