Skip to content

Commit

Permalink
depends: sync bela
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Sep 17, 2023
1 parent cca9a82 commit 6e65c7a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 53 deletions.
2 changes: 1 addition & 1 deletion vendor/bela.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/fcharlie/bela/tree/47836da3a358265302f6618180ae6c83aedfca10
https://github.com/fcharlie/bela/tree/da3e775d8f96a1eb13e7e8cd4f0bb506f06e910f
2 changes: 1 addition & 1 deletion vendor/bela/include/bela/__phmap/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://github.com/greg7mdp/parallel-hashmap.git
77cab8192a879e5d27188f97e8f2080dd7e36ca8
81ca45376940d4bfd56754608c8ed6c1900ab1e9
60 changes: 42 additions & 18 deletions vendor/bela/include/bela/__phmap/phmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1268,21 +1268,16 @@ class raw_hash_set
size_t max_size() const { return (std::numeric_limits<size_t>::max)(); }

PHMAP_ATTRIBUTE_REINITIALIZES void clear() {
// Iterating over this container is O(bucket_count()). When bucket_count()
// is much greater than size(), iteration becomes prohibitively expensive.
// For clear() it is more important to reuse the allocated array when the
// container is small because allocation takes comparatively long time
// compared to destruction of the elements of the container. So we pick the
// largest bucket_count() threshold for which iteration is still fast and
// past that we simply deallocate the array.
if (empty())
return;
if (capacity_ > 127) {
destroy_slots();
} else if (capacity_) {
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
if (capacity_) {
if constexpr (!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||
std::is_same<typename Policy::is_flat, std::false_type>::value) {
// node map or not trivially destructible... we need to iterate and destroy values one by one
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
}
}
}
size_ = 0;
Expand Down Expand Up @@ -2011,12 +2006,19 @@ class raw_hash_set
}

void destroy_slots() {
if (!capacity_) return;
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
if (!capacity_)
return;

if constexpr (!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||
std::is_same<typename Policy::is_flat, std::false_type>::value) {
// node map, or not trivially destructible... we need to iterate and destroy values one by one
// std::cout << "either this is a node map or " << type_name<typename PolicyTraits::value_type>() << " is not trivially_destructible\n";
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
}
}
}
}
auto layout = MakeLayout(capacity_);
// Unpoison before returning the memory to the allocator.
SanitizerUnpoisonMemoryRegion(slots_, sizeof(slot_type) * capacity_);
Expand Down Expand Up @@ -4020,6 +4022,24 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
return std::get<2>(res);
}

// returns {pointer, bool} instead of {iterator, bool} per try_emplace.
// useful for node-based containers, since the pointer is not invalidated by concurrent insert etc.
template <class K = key_type, class... Args>
std::pair<typename parallel_hash_map::parallel_hash_set::pointer, bool> try_emplace_p(K&& k, Args&&... args) {
size_t hashval = this->hash(k);
typename Lockable::UniqueLock m;
auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);
typename Base::Inner *inner = std::get<0>(res);
if (std::get<2>(res)) {
inner->set_.emplace_at(std::get<1>(res), std::piecewise_construct,
std::forward_as_tuple(std::forward<K>(k)),
std::forward_as_tuple(std::forward<Args>(args)...));
inner->set_.set_ctrl(std::get<1>(res), H2(hashval));
}
auto it = this->iterator_at(inner, inner->set_.iterator_at(std::get<1>(res)));
return {&*it, std::get<2>(res)};
}

// ----------- end of phmap extensions --------------------------

template <class K = key_type, class P = Policy, K* = nullptr>
Expand Down Expand Up @@ -4184,6 +4204,7 @@ struct FlatHashSetPolicy
using key_type = T;
using init_type = T;
using constant_iterators = std::true_type;
using is_flat = std::true_type;

template <class Allocator, class... Args>
static void construct(Allocator* alloc, slot_type* slot, Args&&... args) {
Expand Down Expand Up @@ -4226,6 +4247,7 @@ struct FlatHashMapPolicy
using key_type = K;
using mapped_type = V;
using init_type = std::pair</*non const*/ key_type, mapped_type>;
using is_flat = std::true_type;

template <class Allocator, class... Args>
static void construct(Allocator* alloc, slot_type* slot, Args&&... args) {
Expand Down Expand Up @@ -4308,6 +4330,7 @@ struct NodeHashSetPolicy
using key_type = T;
using init_type = T;
using constant_iterators = std::true_type;
using is_flat = std::false_type;

template <class Allocator, class... Args>
static T* new_element(Allocator* alloc, Args&&... args) {
Expand Down Expand Up @@ -4353,6 +4376,7 @@ class NodeHashMapPolicy
using key_type = Key;
using mapped_type = Value;
using init_type = std::pair</*non const*/ key_type, mapped_type>;
using is_flat = std::false_type;

template <class Allocator, class... Args>
static value_type* new_element(Allocator* alloc, Args&&... args) {
Expand Down
20 changes: 16 additions & 4 deletions vendor/bela/include/bela/int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
#define BELA_INTERNAL_WCHAR_T wchar_t
#endif // defined(_MSC_VER)

#ifndef _BLEA_INT128_HAS_CXX23
#if ((defined(_MSVC_LANG) && _MSVC_LANG > 202002L) || __cplusplus > 202002L)
#define _BLEA_INT128_HAS_CXX23 1
#else
#define _BLEA_INT128_HAS_CXX23 0
#endif
#endif // _BLEA_HAS_CXX23

namespace bela {

class int128;
Expand Down Expand Up @@ -254,8 +262,10 @@ template <> class numeric_limits<bela::uint128> {
static constexpr bool has_infinity = false;
static constexpr bool has_quiet_NaN = false;
static constexpr bool has_signaling_NaN = false;
#if !_BLEA_INT128_HAS_CXX23
static constexpr float_denorm_style has_denorm = denorm_absent;
static constexpr bool has_denorm_loss = false;
#endif
static constexpr float_round_style round_style = round_toward_zero;
static constexpr bool is_iec559 = false;
static constexpr bool is_bounded = true;
Expand Down Expand Up @@ -482,8 +492,10 @@ template <> class numeric_limits<bela::int128> {
static constexpr bool has_infinity = false;
static constexpr bool has_quiet_NaN = false;
static constexpr bool has_signaling_NaN = false;
#if !_BLEA_INT128_HAS_CXX23
static constexpr float_denorm_style has_denorm = denorm_absent;
static constexpr bool has_denorm_loss = false;
#endif
static constexpr float_round_style round_style = round_toward_zero;
static constexpr bool is_iec559 = false;
static constexpr bool is_bounded = true;
Expand Down Expand Up @@ -619,8 +631,8 @@ constexpr uint128::uint128(unsigned long long v) : lo_{v}, hi_{0} {}

#ifdef BELA_HAVE_INTRINSIC_INT128
constexpr uint128::uint128(__int128 v)
: lo_{static_cast<uint64_t>(v & ~uint64_t{0})}, hi_{static_cast<uint64_t>(static_cast<unsigned __int128>(v) >>
64)} {}
: lo_{static_cast<uint64_t>(v & ~uint64_t{0})},
hi_{static_cast<uint64_t>(static_cast<unsigned __int128>(v) >> 64)} {}
constexpr uint128::uint128(unsigned __int128 v)
: lo_{static_cast<uint64_t>(v & ~uint64_t{0})}, hi_{static_cast<uint64_t>(v >> 64)} {}
#endif // BELA_HAVE_INTRINSIC_INT128
Expand All @@ -646,8 +658,8 @@ constexpr uint128::uint128(unsigned long long v) : hi_{0}, lo_{v} {}

#ifdef BELA_HAVE_INTRINSIC_INT128
constexpr uint128::uint128(__int128 v)
: hi_{static_cast<uint64_t>(static_cast<unsigned __int128>(v) >> 64)}, lo_{static_cast<uint64_t>(v &
~uint64_t{0})} {}
: hi_{static_cast<uint64_t>(static_cast<unsigned __int128>(v) >> 64)},
lo_{static_cast<uint64_t>(v & ~uint64_t{0})} {}
constexpr uint128::uint128(unsigned __int128 v)
: hi_{static_cast<uint64_t>(v >> 64)}, lo_{static_cast<uint64_t>(v & ~uint64_t{0})} {}
#endif // BELA_HAVE_INTRINSIC_INT128
Expand Down
2 changes: 1 addition & 1 deletion vendor/pugixml.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/zeux/pugixml/tree/980cf57ff4d21e4734c847f0772c1f98fcbff86f
https://github.com/zeux/pugixml/tree/db78afc2b7d8f043b4bc6b185635d949ea2ed2a8
6 changes: 3 additions & 3 deletions vendor/pugixml/pugiconfig.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* pugixml parser - version 1.13
* pugixml parser - version 1.14
* --------------------------------------------------------
* Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Copyright (C) 2006-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Report bugs and download new versions at https://pugixml.org/
*
* This library is distributed under the MIT License. See notice at the end
Expand Down Expand Up @@ -52,7 +52,7 @@
#endif

/**
* Copyright (c) 2006-2022 Arseny Kapoulkine
* Copyright (c) 2006-2023 Arseny Kapoulkine
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand Down
74 changes: 56 additions & 18 deletions vendor/pugixml/pugixml.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* pugixml parser - version 1.13
* pugixml parser - version 1.14
* --------------------------------------------------------
* Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Copyright (C) 2006-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* Report bugs and download new versions at https://pugixml.org/
*
* This library is distributed under the MIT License. See notice at the end
Expand Down Expand Up @@ -3279,6 +3279,7 @@ PUGI_IMPL_NS_BEGIN
char_t ch = 0;
xml_node_struct* cursor = root;
char_t* mark = s;
char_t* merged_pcdata = s;

while (*s != 0)
{
Expand Down Expand Up @@ -3473,21 +3474,38 @@ PUGI_IMPL_NS_BEGIN

if (cursor->parent || PUGI_IMPL_OPTSET(parse_fragment))
{
char_t* parsed_pcdata = s;

s = strconv_pcdata(s);

if (PUGI_IMPL_OPTSET(parse_embed_pcdata) && cursor->parent && !cursor->first_child && !cursor->value)
{
cursor->value = s; // Save the offset.
cursor->value = parsed_pcdata; // Save the offset.
}
else if (PUGI_IMPL_OPTSET(parse_merge_pcdata) && cursor->first_child && PUGI_IMPL_NODETYPE(cursor->first_child->prev_sibling_c) == node_pcdata)
{
assert(merged_pcdata >= cursor->first_child->prev_sibling_c->value);

// Catch up to the end of last parsed value; only needed for the first fragment.
merged_pcdata += strlength(merged_pcdata);

size_t length = strlength(parsed_pcdata);

// Must use memmove instead of memcpy as this move may overlap
memmove(merged_pcdata, parsed_pcdata, (length + 1) * sizeof(char_t));
merged_pcdata += length;
}
else
{
xml_node_struct* prev_cursor = cursor;
PUGI_IMPL_PUSHNODE(node_pcdata); // Append a new node on the tree.

cursor->value = s; // Save the offset.
cursor->value = parsed_pcdata; // Save the offset.
merged_pcdata = parsed_pcdata; // Used for parse_merge_pcdata above, cheaper to save unconditionally

PUGI_IMPL_POPNODE(); // Pop since this is a standalone.
cursor = prev_cursor; // Pop since this is a standalone.
}

s = strconv_pcdata(s);

if (!*s) break;
}
else
Expand Down Expand Up @@ -3566,7 +3584,7 @@ PUGI_IMPL_NS_BEGIN
return make_parse_result(status_unrecognized_tag, length - 1);

// check if there are any element nodes parsed
xml_node_struct* first_root_child_parsed = last_root_child ? last_root_child->next_sibling + 0 : root->first_child+ 0;
xml_node_struct* first_root_child_parsed = last_root_child ? last_root_child->next_sibling + 0 : root->first_child + 0;

if (!PUGI_IMPL_OPTSET(parse_fragment) && !has_element_node_siblings(first_root_child_parsed))
return make_parse_result(status_no_document_element, length - 1);
Expand Down Expand Up @@ -5401,11 +5419,11 @@ namespace pugi
return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs));
}

PUGI_IMPL_FN bool xml_attribute::set_value(const char_t* rhs, size_t sz)
PUGI_IMPL_FN bool xml_attribute::set_name(const char_t* rhs, size_t size)
{
if (!_attr) return false;

return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, sz);
return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, size);
}

PUGI_IMPL_FN bool xml_attribute::set_value(const char_t* rhs)
Expand All @@ -5415,6 +5433,13 @@ namespace pugi
return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs));
}

PUGI_IMPL_FN bool xml_attribute::set_value(const char_t* rhs, size_t size)
{
if (!_attr) return false;

return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, size);
}

PUGI_IMPL_FN bool xml_attribute::set_value(int rhs)
{
if (!_attr) return false;
Expand Down Expand Up @@ -5798,14 +5823,14 @@ namespace pugi
return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs));
}

PUGI_IMPL_FN bool xml_node::set_value(const char_t* rhs, size_t sz)
PUGI_IMPL_FN bool xml_node::set_name(const char_t* rhs, size_t size)
{
xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null;

if (type_ != node_pcdata && type_ != node_cdata && type_ != node_comment && type_ != node_pi && type_ != node_doctype)
if (type_ != node_element && type_ != node_pi && type_ != node_declaration)
return false;

return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, sz);
return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, size);
}

PUGI_IMPL_FN bool xml_node::set_value(const char_t* rhs)
Expand All @@ -5818,6 +5843,16 @@ namespace pugi
return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs));
}

PUGI_IMPL_FN bool xml_node::set_value(const char_t* rhs, size_t size)
{
xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null;

if (type_ != node_pcdata && type_ != node_cdata && type_ != node_comment && type_ != node_pi && type_ != node_doctype)
return false;

return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, size);
}

PUGI_IMPL_FN xml_attribute xml_node::append_attribute(const char_t* name_)
{
if (!impl::allow_insert_attribute(type())) return xml_attribute();
Expand Down Expand Up @@ -6286,6 +6321,9 @@ namespace pugi
// append_buffer is only valid for elements/documents
if (!impl::allow_insert_child(type(), node_element)) return impl::make_parse_result(status_append_invalid_root);

// append buffer can not merge PCDATA into existing PCDATA nodes
if ((options & parse_merge_pcdata) != 0 && last_child().type() == node_pcdata) return impl::make_parse_result(status_append_invalid_root);

// get document node
impl::xml_document_struct* doc = &impl::get_document(_root);

Expand Down Expand Up @@ -6690,18 +6728,18 @@ namespace pugi
}
#endif

PUGI_IMPL_FN bool xml_text::set(const char_t* rhs, size_t sz)
PUGI_IMPL_FN bool xml_text::set(const char_t* rhs)
{
xml_node_struct* dn = _data_new();

return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, sz) : false;
return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)) : false;
}

PUGI_IMPL_FN bool xml_text::set(const char_t* rhs)
PUGI_IMPL_FN bool xml_text::set(const char_t* rhs, size_t size)
{
xml_node_struct* dn = _data_new();

return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)) : false;
return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, size) : false;
}

PUGI_IMPL_FN bool xml_text::set(int rhs)
Expand Down Expand Up @@ -13163,7 +13201,7 @@ namespace pugi
#endif

/**
* Copyright (c) 2006-2022 Arseny Kapoulkine
* Copyright (c) 2006-2023 Arseny Kapoulkine
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand Down
Loading

0 comments on commit 6e65c7a

Please sign in to comment.