summaryrefslogtreecommitdiffstats
path: root/src/shared_buffer.hh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/shared_buffer.hh45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/shared_buffer.hh b/src/shared_buffer.hh
index e0029e9..5fe26d0 100644
--- a/src/shared_buffer.hh
+++ b/src/shared_buffer.hh
@@ -39,15 +39,17 @@
#include <string.h>
#include <sys/types.h>
-#include "base/attr_line.hh"
#include "base/auto_mem.hh"
#include "base/file_range.hh"
#include "base/intern_string.hh"
+#include "base/line_range.hh"
#include "base/lnav_log.hh"
#include "scn/util/string_view.h"
class shared_buffer;
+#define SHARED_BUFFER_TRACE 0
+
struct shared_buffer_ref {
public:
shared_buffer_ref(char* data = nullptr, size_t len = 0)
@@ -57,28 +59,23 @@ public:
~shared_buffer_ref() { this->disown(); }
- shared_buffer_ref(const shared_buffer_ref& other)
- {
- this->sb_owner = nullptr;
- this->sb_data = nullptr;
- this->sb_length = 0;
- this->sb_metadata = file_range::metadata{};
-
- this->copy_ref(other);
- }
+ shared_buffer_ref(const shared_buffer_ref& other) = delete;
shared_buffer_ref(shared_buffer_ref&& other) noexcept;
- shared_buffer_ref& operator=(const shared_buffer_ref& other)
+ shared_buffer_ref& operator=(const shared_buffer_ref& other) = delete;
+
+ shared_buffer_ref clone() const
{
- if (this != &other) {
- this->disown();
- this->copy_ref(other);
- }
+ shared_buffer_ref retval;
- return *this;
+ retval.copy_ref(*this);
+
+ return retval;
}
+ shared_buffer_ref& operator=(shared_buffer_ref&& other);
+
bool empty() const
{
return this->sb_data == nullptr || this->sb_length == 0;
@@ -165,7 +162,9 @@ public:
private:
void copy_ref(const shared_buffer_ref& other);
+#if SHARED_BUFFER_TRACE
auto_mem<char*> sb_backtrace;
+#endif
file_range::metadata sb_metadata;
shared_buffer* sb_owner;
const char* sb_data;
@@ -194,20 +193,6 @@ public:
std::vector<shared_buffer_ref*> sb_refs;
};
-struct tmp_shared_buffer {
- explicit tmp_shared_buffer(const char* str, size_t len = -1)
- {
- if (len == (size_t) -1) {
- len = strlen(str);
- }
-
- this->tsb_ref.share(this->tsb_manager, (char*) str, len);
- };
-
- shared_buffer tsb_manager;
- shared_buffer_ref tsb_ref;
-};
-
inline std::string
to_string(const shared_buffer_ref& sbr)
{