summaryrefslogtreecommitdiffstats
path: root/src/shared_buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared_buffer.cc')
-rw-r--r--src/shared_buffer.cc50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/shared_buffer.cc b/src/shared_buffer.cc
index 39e21be..ff51750 100644
--- a/src/shared_buffer.cc
+++ b/src/shared_buffer.cc
@@ -40,19 +40,15 @@
#include "base/ansi_scrubber.hh"
#include "shared_buffer.hh"
-static const bool DEBUG_TRACE = false;
-
void
shared_buffer_ref::share(shared_buffer& sb, const char* data, size_t len)
{
-#ifdef HAVE_EXECINFO_H
- if (DEBUG_TRACE) {
- void* frames[128];
- int rc;
+#if SHARED_BUFFER_TRACE
+ void* frames[128];
+ int rc;
- rc = backtrace(frames, 128);
- this->sb_backtrace.reset(backtrace_symbols(frames, rc));
- }
+ rc = backtrace(frames, 128);
+ this->sb_backtrace.reset(backtrace_symbols(frames, rc));
#endif
this->disown();
@@ -95,8 +91,36 @@ shared_buffer_ref::shared_buffer_ref(shared_buffer_ref&& other) noexcept
this->sb_data = nullptr;
this->sb_length = 0;
} else if (other.sb_owner != nullptr) {
- auto owner_ref_iter = std::find(other.sb_owner->sb_refs.begin(),
- other.sb_owner->sb_refs.end(),
+ auto owner_ref_iter = std::find(other.sb_owner->sb_refs.rbegin(),
+ other.sb_owner->sb_refs.rend(),
+ &other);
+ *owner_ref_iter = this;
+ this->sb_owner = std::exchange(other.sb_owner, nullptr);
+ this->sb_data = std::exchange(other.sb_data, nullptr);
+ this->sb_length = std::exchange(other.sb_length, 0);
+ } else {
+ this->sb_owner = nullptr;
+ this->sb_data = other.sb_data;
+ this->sb_length = other.sb_length;
+ other.sb_data = nullptr;
+ other.sb_length = 0;
+ }
+ this->sb_metadata = other.sb_metadata;
+ other.sb_metadata = {};
+}
+
+shared_buffer_ref&
+shared_buffer_ref::operator=(shared_buffer_ref&& other)
+{
+ this->disown();
+
+ if (other.sb_data == nullptr) {
+ this->sb_owner = nullptr;
+ this->sb_data = nullptr;
+ this->sb_length = 0;
+ } else if (other.sb_owner != nullptr) {
+ auto owner_ref_iter = std::find(other.sb_owner->sb_refs.rbegin(),
+ other.sb_owner->sb_refs.rend(),
&other);
*owner_ref_iter = this;
this->sb_owner = std::exchange(other.sb_owner, nullptr);
@@ -111,6 +135,8 @@ shared_buffer_ref::shared_buffer_ref(shared_buffer_ref&& other) noexcept
}
this->sb_metadata = other.sb_metadata;
other.sb_metadata = {};
+
+ return *this;
}
bool
@@ -190,7 +216,7 @@ shared_buffer_ref::widen(narrow_result old_data_length)
void
shared_buffer_ref::erase_ansi()
{
- if (!this->sb_metadata.m_has_ansi) {
+ if (!this->sb_metadata.m_valid_utf || !this->sb_metadata.m_has_ansi) {
return;
}