Skip to content

Commit

Permalink
::clone check parent.
Browse files Browse the repository at this point in the history
  • Loading branch information
vztpv authored Aug 16, 2024
1 parent 94f37ee commit 1470373
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
19 changes: 13 additions & 6 deletions claujson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <execution>

#include "fmt/format.h"
//#include "rapidjson/writer.h"


#define claujson_inline _simdjson_inline
Expand Down Expand Up @@ -1305,7 +1304,11 @@ namespace claujson {
uint64_t sz = this->get_data_size();

for (uint64_t i = 0; i < sz; ++i) {
result->add_object_element(this->get_key_list(i).clone(), this->get_value_list(i).clone());
auto x = this->get_value_list(i).clone();
if (x.as_structured_ptr()) {
x.as_structured_ptr()->set_parent(dynamic_cast<Structured*>(const_cast<Object*>(this)));
}
result->add_object_element(this->get_key_list(i).clone(), std::move(x));
}

return result;
Expand Down Expand Up @@ -1620,7 +1623,11 @@ namespace claujson {

uint64_t sz = this->get_data_size();
for (uint64_t i = 0; i < sz; ++i) {
result->add_array_element(this->get_value_list(i).clone());
auto x = this->get_value_list(i).clone();
if (x.as_structured_ptr()) {
x.as_structured_ptr()->set_parent(dynamic_cast<Structured*>(const_cast<Array*>(this)));
}
result->add_array_element(std::move(x));
}

return result;
Expand Down Expand Up @@ -3525,7 +3532,7 @@ namespace claujson {
std::string write_to_str2(const _Value& data, bool pretty);

void write_parallel(const std::string& fileName, _Value& j, uint64_t thr_num, bool pretty);
void write_parallel2(const std::string& fileName, _Value& j, uint64_t thr_num, bool pretty);
void write_parallel2(const std::string& fileName, const _Value& j, uint64_t thr_num, bool pretty);

};

Expand Down Expand Up @@ -4386,7 +4393,7 @@ namespace claujson {
}
}

void LoadData2::write_parallel2(const std::string& fileName, _Value& j, uint64_t thr_num, bool pretty) {
void LoadData2::write_parallel2(const std::string& fileName, const _Value& j, uint64_t thr_num, bool pretty) {
if (!j.is_structured()) {
write(fileName, j, pretty, false);
return;
Expand Down Expand Up @@ -6100,7 +6107,7 @@ namespace claujson {
LoadData2 p(pool.get());
p.write_parallel(fileName, j, thr_num, pretty);
}
void writer::write_parallel2(const std::string& fileName, _Value& j, uint64_t thr_num, bool pretty) {
void writer::write_parallel2(const std::string& fileName, const _Value& j, uint64_t thr_num, bool pretty) {
LoadData2 p(pool.get());
p.write_parallel2(fileName, j, thr_num, pretty);
}
Expand Down
2 changes: 1 addition & 1 deletion claujson.h
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ namespace claujson {
void write(const std::string& fileName, const _Value& global, bool pretty = false);

void write_parallel(const std::string& fileName, _Value& j, uint64_t thr_num, bool pretty = false);
void write_parallel2(const std::string& fileName, _Value& j, uint64_t thr_num, bool pretty = false);
void write_parallel2(const std::string& fileName, const _Value& j, uint64_t thr_num, bool pretty = false);
};


Expand Down
8 changes: 4 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// mainly tested with C++17...

#include "mimalloc-new-delete.h"

#include <iostream>
#include <string>
#include <ctime>
Expand Down Expand Up @@ -309,10 +310,9 @@ int main(int argc, char* argv[])


//debug test
//std::cout << j << "\n";
///claujson::clean(j);
//continue;
//return 0;
// //std::cout << j << "\n";
// std::cout << "chk\n";
// return 0;
//
//

Expand Down

0 comments on commit 1470373

Please sign in to comment.