-
Notifications
You must be signed in to change notification settings - Fork 98
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
option to check duplicate object keys #801
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,19 +518,43 @@ namespace detail { | |
unchecked_object:: | ||
~unchecked_object() | ||
{ | ||
if(! data_) | ||
return; | ||
if(sp_.is_not_shared_and_deallocate_is_trivial()) | ||
return; | ||
value* p = data_; | ||
while(size_--) | ||
|
||
for( value* p = data_; p != end_; p += 2 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change this loop? I prefer the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see why, because the loop is simpler. |
||
{ | ||
p[0].~value(); | ||
p[1].~value(); | ||
p += 2; | ||
} | ||
} | ||
|
||
unchecked_object:: | ||
unchecked_object( | ||
value* data, | ||
std::size_t size, | ||
storage_ptr const& sp, | ||
bool ignore_duplicates) noexcept | ||
: data_(data) | ||
, end_(data + 2 * size) | ||
, sp_(sp) | ||
, ignore_duplicates_(ignore_duplicates) | ||
{ | ||
} | ||
|
||
std::size_t | ||
unchecked_object:: | ||
size() const noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we move this from a header that wasn't visible to a header that is visible? |
||
{ | ||
return std::size_t(end_ - data_) / 2; | ||
} | ||
|
||
void | ||
unchecked_object:: | ||
pop_front() noexcept | ||
{ | ||
data_ += 2; | ||
} | ||
|
||
} // detail | ||
|
||
BOOST_JSON_NS_END | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,7 +197,7 @@ destroy() noexcept | |
//---------------------------------------------------------- | ||
|
||
object:: | ||
object(detail::unchecked_object&& uo) | ||
object(detail::unchecked_object& uo) | ||
: sp_(uo.storage()) | ||
{ | ||
if(uo.size() == 0) | ||
|
@@ -210,20 +210,18 @@ object(detail::unchecked_object&& uo) | |
uo.size() <= max_size()); | ||
t_ = table::allocate( | ||
uo.size(), 0, sp_); | ||
t_->size = 0; | ||
|
||
// insert all elements, keeping | ||
// the last of any duplicate keys. | ||
// the last of any duplicate keys, unless uo.ignore_duplicates is false. | ||
auto dest = begin(); | ||
auto src = uo.release(); | ||
auto const end = src + 2 * uo.size(); | ||
if(t_->is_small()) | ||
{ | ||
t_->size = 0; | ||
while(src != end) | ||
for( ; uo.size(); uo.pop_front() ) | ||
{ | ||
auto src = uo.front(); | ||
access::construct_key_value_pair( | ||
dest, pilfer(src[0]), pilfer(src[1])); | ||
src += 2; | ||
auto result = detail::find_in_object(*this, dest->key()); | ||
if(! result.first) | ||
{ | ||
|
@@ -232,6 +230,11 @@ object(detail::unchecked_object&& uo) | |
continue; | ||
} | ||
// handle duplicate | ||
if( !uo.ignore_duplicate_keys() ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a constant in the loop, so you should lift the conditional out of the loop |
||
{ | ||
dest->~key_value_pair(); | ||
return; | ||
} | ||
auto& v = *result.first; | ||
// don't bother to check if | ||
// storage deallocate is trivial | ||
|
@@ -243,11 +246,11 @@ object(detail::unchecked_object&& uo) | |
} | ||
return; | ||
} | ||
while(src != end) | ||
for( ; uo.size() ; uo.pop_front() ) | ||
{ | ||
auto src = uo.front(); | ||
access::construct_key_value_pair( | ||
dest, pilfer(src[0]), pilfer(src[1])); | ||
src += 2; | ||
auto& head = t_->bucket(dest->key()); | ||
auto i = head; | ||
for(;;) | ||
|
@@ -260,6 +263,7 @@ object(detail::unchecked_object&& uo) | |
head = static_cast<index_t>( | ||
dest - begin()); | ||
++dest; | ||
++t_->size; | ||
break; | ||
} | ||
auto& v = (*t_)[i]; | ||
|
@@ -270,6 +274,11 @@ object(detail::unchecked_object&& uo) | |
} | ||
|
||
// handle duplicate | ||
if( !uo.ignore_duplicate_keys() ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a constant in the loop, so you should lift the conditional out of the loop |
||
{ | ||
dest->~key_value_pair(); | ||
return; | ||
} | ||
access::next(*dest) = | ||
access::next(v); | ||
// don't bother to check if | ||
|
@@ -282,8 +291,6 @@ object(detail::unchecked_object&& uo) | |
break; | ||
} | ||
} | ||
t_->size = static_cast< | ||
index_t>(dest - begin()); | ||
} | ||
|
||
object:: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
inline
goes on the definition not the declaration (my fault)