Upgrade libosmium to v2.15.6

This commit is contained in:
Desone Burns II
2020-11-17 14:59:06 -07:00
parent 98fd17589d
commit dfc1bfc27e
319 changed files with 6268 additions and 3946 deletions
+148 -18
View File
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -101,14 +101,16 @@ namespace osmium {
// This is needed so we can call std::back_inserter() on a Buffer.
using value_type = Item;
enum class auto_grow : bool {
yes = true,
no = false
enum class auto_grow {
no = 0,
yes = 1,
internal = 2
}; // enum class auto_grow
private:
std::unique_ptr<unsigned char[]> m_memory;
std::unique_ptr<Buffer> m_next_buffer;
std::unique_ptr<unsigned char[]> m_memory{};
unsigned char* m_data = nullptr;
std::size_t m_capacity = 0;
std::size_t m_written = 0;
@@ -120,14 +122,35 @@ namespace osmium {
std::function<void(Buffer&)> m_full;
static std::size_t calculate_capacity(std::size_t capacity) noexcept {
// The majority of all Nodes will fit into this size.
constexpr static const std::size_t min_capacity = 64;
enum {
// The majority of all Nodes will fit into this size.
min_capacity = 64
};
if (capacity < min_capacity) {
return min_capacity;
}
return padded_length(capacity);
}
void grow_internal() {
assert(m_data && "This must be a valid buffer");
if (!m_memory) {
throw std::logic_error{"Can't grow Buffer if it doesn't use internal memory management."};
}
std::unique_ptr<Buffer> old{new Buffer{std::move(m_memory), m_capacity, m_committed}};
m_memory = std::unique_ptr<unsigned char[]>{new unsigned char[m_capacity]};
m_data = m_memory.get();
m_written -= m_committed;
std::copy_n(old->data() + m_committed, m_written, m_data);
m_committed = 0;
old->m_next_buffer = std::move(m_next_buffer);
m_next_buffer = std::move(old);
}
public:
/**
@@ -139,7 +162,7 @@ namespace osmium {
* buffer.
*/
Buffer() noexcept :
m_memory() {
m_next_buffer() {
}
/**
@@ -153,7 +176,7 @@ namespace osmium {
* the alignment.
*/
explicit Buffer(unsigned char* data, std::size_t size) :
m_memory(),
m_next_buffer(),
m_data(data),
m_capacity(size),
m_written(size),
@@ -176,7 +199,7 @@ namespace osmium {
* than capacity.
*/
explicit Buffer(unsigned char* data, std::size_t capacity, std::size_t committed) :
m_memory(),
m_next_buffer(),
m_data(data),
m_capacity(capacity),
m_written(committed),
@@ -192,6 +215,37 @@ namespace osmium {
}
}
/**
* Constructs a valid internally memory-managed buffer with the
* given capacity that already contains 'committed' bytes of data.
*
* @param data A unique pointer to some (possibly initialized) data.
* The Buffer will manage this memory.
* @param capacity The size of the memory for this buffer.
* @param committed The size of the initialized data. If this is 0, the buffer startes out empty.
*
* @throws std::invalid_argument if the capacity or committed isn't
* a multiple of the alignment or if committed is larger
* than capacity.
*/
explicit Buffer(std::unique_ptr<unsigned char[]> data, std::size_t capacity, std::size_t committed) :
m_next_buffer(),
m_memory(std::move(data)),
m_data(m_memory.get()),
m_capacity(capacity),
m_written(committed),
m_committed(committed) {
if (capacity % align_bytes != 0) {
throw std::invalid_argument{"buffer capacity needs to be multiple of alignment"};
}
if (committed % align_bytes != 0) {
throw std::invalid_argument{"buffer parameter 'committed' needs to be multiple of alignment"};
}
if (committed > capacity) {
throw std::invalid_argument{"buffer parameter 'committed' can not be larger than capacity"};
}
}
/**
* Constructs a valid internally memory-managed buffer with the
* given capacity.
@@ -205,6 +259,7 @@ namespace osmium {
* becomes to small?
*/
explicit Buffer(std::size_t capacity, auto_grow auto_grow = auto_grow::yes) :
m_next_buffer(),
m_memory(new unsigned char[calculate_capacity(capacity)]),
m_data(m_memory.get()),
m_capacity(calculate_capacity(capacity)),
@@ -216,10 +271,50 @@ namespace osmium {
Buffer& operator=(const Buffer&) = delete;
// buffers can be moved
Buffer(Buffer&&) = default;
Buffer& operator=(Buffer&&) = default;
Buffer(Buffer&& other) noexcept :
m_next_buffer(std::move(other.m_next_buffer)),
m_memory(std::move(other.m_memory)),
m_data(other.m_data),
m_capacity(other.m_capacity),
m_written(other.m_written),
m_committed(other.m_committed),
#ifndef NDEBUG
m_builder_count(other.m_builder_count),
#endif
m_auto_grow(other.m_auto_grow),
m_full(std::move(other.m_full)) {
other.m_data = nullptr;
other.m_capacity = 0;
other.m_written = 0;
other.m_committed = 0;
#ifndef NDEBUG
other.m_builder_count = 0;
#endif
}
~Buffer() = default;
Buffer& operator=(Buffer&& other) noexcept {
m_next_buffer = std::move(other.m_next_buffer);
m_memory = std::move(other.m_memory);
m_data = other.m_data;
m_capacity = other.m_capacity;
m_written = other.m_written;
m_committed = other.m_committed;
#ifndef NDEBUG
m_builder_count = other.m_builder_count;
#endif
m_auto_grow = other.m_auto_grow;
m_full = std::move(other.m_full);
other.m_data = nullptr;
other.m_capacity = 0;
other.m_written = 0;
other.m_committed = 0;
#ifndef NDEBUG
other.m_builder_count = 0;
#endif
return *this;
}
~Buffer() noexcept = default;
#ifndef NDEBUG
void increment_builder_count() noexcept {
@@ -324,7 +419,7 @@ namespace osmium {
}
size = calculate_capacity(size);
if (m_capacity < size) {
std::unique_ptr<unsigned char[]> memory(new unsigned char[size]);
std::unique_ptr<unsigned char[]> memory{new unsigned char[size]};
std::copy_n(m_memory.get(), m_capacity, memory.get());
using std::swap;
swap(m_memory, memory);
@@ -333,6 +428,31 @@ namespace osmium {
}
}
/**
* Does this buffer have nested buffers inside. This happens
* when a buffer is full and auto_grow is defined as internal.
*
* @returns Are there nested buffers or not?
*/
bool has_nested_buffers() const noexcept {
return m_next_buffer != nullptr;
}
/**
* Return the most deeply nested buffer. The buffer will be moved
* out.
*
* @pre has_nested_buffers()
*/
std::unique_ptr<Buffer> get_last_nested() {
assert(has_nested_buffers());
Buffer* buffer = this;
while (buffer->m_next_buffer->has_nested_buffers()) {
buffer = buffer->m_next_buffer.get();
}
return std::move(buffer->m_next_buffer);
}
/**
* Mark currently written bytes in the buffer as committed.
*
@@ -397,6 +517,7 @@ namespace osmium {
template <typename T>
T& get(const std::size_t offset) const {
assert(m_data && "This must be a valid buffer");
assert(offset % alignof(T) == 0 && "Wrong alignment");
return *reinterpret_cast<T*>(&m_data[offset]);
}
@@ -441,15 +562,19 @@ namespace osmium {
}
// if there's still not enough space, then try growing the buffer.
if (m_written + size > m_capacity) {
if (m_memory && (m_auto_grow == auto_grow::yes)) {
if (!m_memory || m_auto_grow == auto_grow::no) {
throw osmium::buffer_is_full{};
}
if (m_auto_grow == auto_grow::internal && m_committed != 0) {
grow_internal();
}
if (m_written + size > m_capacity) {
// double buffer size until there is enough space
std::size_t new_capacity = m_capacity * 2;
while (m_written + size > new_capacity) {
new_capacity *= 2;
}
grow(new_capacity);
} else {
throw osmium::buffer_is_full{};
}
}
unsigned char* data = &m_data[m_written];
@@ -590,6 +715,7 @@ namespace osmium {
template <typename T>
t_iterator<T> get_iterator(std::size_t offset) {
assert(m_data && "This must be a valid buffer");
assert(offset % alignof(T) == 0 && "Wrong alignment");
return {m_data + offset, m_data + m_committed};
}
@@ -604,6 +730,7 @@ namespace osmium {
*/
iterator get_iterator(std::size_t offset) {
assert(m_data && "This must be a valid buffer");
assert(offset % alignof(OSMEntity) == 0 && "Wrong alignment");
return {m_data + offset, m_data + m_committed};
}
@@ -648,11 +775,13 @@ namespace osmium {
template <typename T>
t_const_iterator<T> get_iterator(std::size_t offset) const {
assert(m_data && "This must be a valid buffer");
assert(offset % alignof(T) == 0 && "Wrong alignment");
return {m_data + offset, m_data + m_committed};
}
const_iterator get_iterator(std::size_t offset) const {
assert(m_data && "This must be a valid buffer");
assert(offset % alignof(OSMEntity) == 0 && "Wrong alignment");
return {m_data + offset, m_data + m_committed};
}
@@ -695,6 +824,7 @@ namespace osmium {
void swap(Buffer& other) {
using std::swap;
swap(m_next_buffer, other.m_next_buffer);
swap(m_memory, other.m_memory);
swap(m_data, other.m_data);
swap(m_capacity, other.m_capacity);
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -76,8 +76,13 @@ namespace osmium {
private:
static constexpr const std::size_t default_initial_buffer_size = 1024 * 1024;
static constexpr const std::size_t default_max_buffer_size = 800 * 1024;
enum {
default_initial_buffer_size = 1024UL * 1024UL
};
enum {
default_max_buffer_size = 800UL * 1024UL
};
osmium::memory::Buffer m_buffer;
std::size_t m_initial_buffer_size;
+10 -10
View File
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -75,7 +75,7 @@ namespace osmium {
}
CollectionIterator<TMember> operator++(int) {
CollectionIterator<TMember> tmp(*this);
CollectionIterator<TMember> tmp{*this};
operator++();
return tmp;
}
@@ -85,7 +85,7 @@ namespace osmium {
}
bool operator!=(const CollectionIterator<TMember>& rhs) const noexcept {
return m_data != rhs.m_data;
return !(*this == rhs);
}
unsigned char* data() const noexcept {
@@ -123,11 +123,11 @@ namespace osmium {
using const_reference = const TMember&;
using iterator = CollectionIterator<TMember>;
using const_iterator = CollectionIterator<const TMember>;
using size_type = size_t;
using size_type = std::size_t;
static constexpr osmium::item_type itemtype = TCollectionItemType;
constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
constexpr static bool is_compatible_to(const osmium::item_type t) noexcept {
return t == itemtype;
}
@@ -154,19 +154,19 @@ namespace osmium {
}
iterator begin() noexcept {
return iterator(data() + sizeof(Collection<TMember, TCollectionItemType>));
return iterator{data() + sizeof(Collection<TMember, TCollectionItemType>)};
}
iterator end() noexcept {
return iterator(data() + byte_size());
return iterator{data() + byte_size()};
}
const_iterator cbegin() const noexcept {
return const_iterator(data() + sizeof(Collection<TMember, TCollectionItemType>));
return const_iterator{data() + sizeof(Collection<TMember, TCollectionItemType>)};
}
const_iterator cend() const noexcept {
return const_iterator(data() + byte_size());
return const_iterator{data() + byte_size()};
}
const_iterator begin() const noexcept {
+8 -6
View File
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -57,7 +57,9 @@ namespace osmium {
using item_size_type = uint32_t;
// align datastructures to this many bytes
constexpr const std::size_t align_bytes = 8;
enum : std::size_t {
align_bytes = 8UL
};
inline constexpr std::size_t padded_length(std::size_t length) noexcept {
return (length + align_bytes - 1) & ~(align_bytes - 1);
@@ -123,7 +125,7 @@ namespace osmium {
protected:
explicit Item(item_size_type size = 0, item_type type = item_type()) noexcept :
explicit Item(item_size_type size = 0, item_type type = item_type{}) noexcept :
m_size(size),
m_type(type),
m_removed(false),
@@ -174,7 +176,7 @@ namespace osmium {
return m_removed;
}
void set_removed(bool removed) noexcept {
void set_removed(const bool removed) noexcept {
m_removed = removed;
}
@@ -187,7 +189,7 @@ namespace osmium {
return diff_chars[m_diff];
}
void set_diff(diff_indicator_type diff) noexcept {
void set_diff(const diff_indicator_type diff) noexcept {
m_diff = uint16_t(diff);
}
@@ -3,9 +3,9 @@
/*
This file is part of Osmium (http://osmcode.org/libosmium).
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2018 Jochen Topf <jochen@topf.org> and others (see README).
Copyright 2013-2020 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
@@ -49,7 +49,7 @@ namespace osmium {
namespace detail {
template <typename T>
constexpr inline bool type_is_compatible(osmium::item_type t) noexcept {
constexpr inline bool type_is_compatible(const osmium::item_type t) noexcept {
return T::is_compatible_to(t);
}
@@ -120,7 +120,7 @@ namespace osmium {
}
ItemIterator<TMember> operator++(int) noexcept {
ItemIterator<TMember> tmp(*this);
ItemIterator<TMember> tmp{*this};
operator++();
return tmp;
}
@@ -223,7 +223,7 @@ namespace osmium {
*
* Complexity: Linear in the number of items.
*/
size_t size() const noexcept {
std::size_t size() const noexcept {
if (m_begin == m_end) {
return 0;
}