From 5d49e98984b206ae46ea3330a3305c55be48d777 Mon Sep 17 00:00:00 2001 From: Aleksandr Cherenkov Date: Mon, 18 Mar 2024 17:00:21 +0000 Subject: [PATCH] use separate function to print zeroes, use arrays for printing instead of vectors(works faster after this optimization) #569 --- bin/assigner/src/main.cpp | 43 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/bin/assigner/src/main.cpp b/bin/assigner/src/main.cpp index 46db6883..9c59ac84 100644 --- a/bin/assigner/src/main.cpp +++ b/bin/assigner/src/main.cpp @@ -179,13 +179,25 @@ void print_size_t( ) { using TTypeBase = nil::marshalling::field_type; auto integer_container = nil::marshalling::types::integral(input); - std::vector char_vector; - char_vector.resize(integer_container.length(), 0x00); - auto write_iter = char_vector.begin(); - nil::marshalling::status_type status = integer_container.write(write_iter, char_vector.size()); - out.write(reinterpret_cast(char_vector.data()), char_vector.size()); + std::array char_array{}; + auto write_iter = char_array.begin(); + ASSERT(integer_container.write(write_iter, char_array.size()) == nil::marshalling::status_type::success); + out.write(reinterpret_cast(char_array.data()), char_array.size()); } +template +inline void print_zero_field( + std::ostream &out +) { + using TTypeBase = nil::marshalling::field_type; + using AssignmentTableType = assignment_proxy; + using field_element = nil::crypto3::marshalling::types::field_element< + TTypeBase, typename AssignmentTableType::field_type::value_type>; + std::array array{}; + out.write(reinterpret_cast(array.data()), array.size()); +} + + template void print_field( const typename assignment_proxy::field_type::value_type &input, @@ -194,11 +206,10 @@ void print_field( using TTypeBase = nil::marshalling::field_type; using AssignmentTableType = assignment_proxy; auto field_container = nil::crypto3::marshalling::types::field_element(input); - std::vector char_vector; - char_vector.resize(field_container.length(), 0x00); - auto write_iter = char_vector.begin(); - nil::marshalling::status_type status = field_container.write(write_iter, char_vector.size()); - out.write(reinterpret_cast(char_vector.data()), char_vector.size()); + std::array char_array{}; + auto write_iter = char_array.begin(); + ASSERT(field_container.write(write_iter, char_array.size()) == nil::marshalling::status_type::success); + out.write(reinterpret_cast(char_array.data()), char_array.size()); } template @@ -211,7 +222,7 @@ void print_vector_value( if (i < table_col.size()) { print_field(table_col[i], out); } else { - print_field(0, out); + print_zero_field(out); } } } @@ -328,7 +339,7 @@ void print_assignment_table(const assignment_proxy &table_p } ASSERT(offset < padded_rows_amount); while(offset < padded_rows_amount) { - print_field(0, out); + print_zero_field(out); offset++; } witness_idx += padded_rows_amount; @@ -358,7 +369,7 @@ void print_assignment_table(const assignment_proxy &table_p } ASSERT(offset < padded_rows_amount); while(offset < padded_rows_amount) { - print_field(0, out); + print_zero_field(out); offset++; } @@ -381,15 +392,15 @@ void print_assignment_table(const assignment_proxy &table_p if (selector_rows.find(j) != selector_rows.end()) { print_field(table_proxy.selector(i, j), out); } else { - print_field(0, out); + print_zero_field(out); } offset++; } } ASSERT(offset < padded_rows_amount); while(offset < padded_rows_amount) { - print_field(0, out); - offset++; + print_zero_field(out); + offset++; } selector_idx += padded_rows_amount;