From 58d249ca16f12625ae8c2ee9788a263d296b0684 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Sat, 9 Nov 2019 10:34:32 -0500 Subject: [PATCH] Introducing move assignments. (#363) --- include/simdjson/padded_string.h | 9 +++++++++ include/simdjson/parsedjson.h | 1 + src/parsedjson.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/include/simdjson/padded_string.h b/include/simdjson/padded_string.h index d8f3c781d..5b3864e19 100644 --- a/include/simdjson/padded_string.h +++ b/include/simdjson/padded_string.h @@ -42,6 +42,15 @@ public: : viable_size(o.viable_size), data_ptr(o.data_ptr) { o.data_ptr = nullptr; // we take ownership } + + padded_string &operator=(padded_string &&o) { + data_ptr = o.data_ptr; + viable_size = o.viable_size; + o.data_ptr = nullptr; // we take ownership + o.viable_size = 0; + return *this; + } + void swap(padded_string &o) { size_t tmp_viable_size = viable_size; char *tmp_data_ptr = data_ptr; diff --git a/include/simdjson/parsedjson.h b/include/simdjson/parsedjson.h index ef0122928..4a80234a9 100644 --- a/include/simdjson/parsedjson.h +++ b/include/simdjson/parsedjson.h @@ -24,6 +24,7 @@ public: ParsedJson(); ~ParsedJson(); ParsedJson(ParsedJson &&p); + ParsedJson &operator=(ParsedJson &&o); // if needed, allocate memory so that the object is able to process JSON // documents having up to len bytes and max_depth "depth" diff --git a/src/parsedjson.cpp b/src/parsedjson.cpp index 0c6a1bdb9..709779c0b 100644 --- a/src/parsedjson.cpp +++ b/src/parsedjson.cpp @@ -25,6 +25,36 @@ ParsedJson::ParsedJson(ParsedJson &&p) p.current_string_buf_loc = nullptr; } +ParsedJson &ParsedJson::operator=(ParsedJson &&p) { + byte_capacity = p.byte_capacity; + p.byte_capacity = 0; + depth_capacity = p.depth_capacity; + p.depth_capacity = 0; + tape_capacity = p.tape_capacity; + p.tape_capacity = 0; + string_capacity = p.string_capacity; + p.string_capacity = 0; + current_loc = p.current_loc; + p.current_loc = 0; + n_structural_indexes = p.n_structural_indexes; + p.n_structural_indexes = 0; + structural_indexes = p.structural_indexes; + p.structural_indexes = nullptr; + tape = p.tape; + p.tape = nullptr; + containing_scope_offset = p.containing_scope_offset; + p.containing_scope_offset = nullptr; + ret_address = p.ret_address; + p.ret_address = nullptr; + string_buf = p.string_buf; + p.string_buf = nullptr; + current_string_buf_loc = p.current_string_buf_loc; + p.current_string_buf_loc = nullptr; + valid = p.valid; + p.valid = false; + return *this; +} + WARN_UNUSED bool ParsedJson::allocate_capacity(size_t len, size_t max_depth) { if (max_depth <= 0) {