mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
[C++] Update to address comparator failure in big endian (#7681)
* update unit test and generated file to test is extra endianswap can help resolve issue * remove EndianScalar wrapper from Get method * remove endianscalar wrapper * update * update * use Array instead * clang format * address error * clang * update * manually generate * Move Nim to completed language * Add swift link * address comments * update unit test * address comment * address comment * regenerate file * use auto instead of size_t * use uint32_t instead * update * format * delete extra whitespace Co-authored-by: Wen Sun <sunwen@google.com> Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -2269,15 +2269,18 @@ class CppGenerator : public BaseGenerator {
|
||||
code_.SetValue("INPUT_TYPE", input_type);
|
||||
code_ +=
|
||||
" int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}"
|
||||
") const { ";
|
||||
code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {";
|
||||
code_ += " const auto {{FIELD_NAME}}_l = {{FIELD_NAME}}_[i];";
|
||||
code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);";
|
||||
code_ += " if({{FIELD_NAME}}_l != {{FIELD_NAME}}_r) ";
|
||||
") const {";
|
||||
code_ +=
|
||||
" return static_cast<int>({{FIELD_NAME}}_l > "
|
||||
"{{FIELD_NAME}}_r)"
|
||||
" - static_cast<int>({{FIELD_NAME}}_l < {{FIELD_NAME}}_r);";
|
||||
" const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();";
|
||||
code_ +=
|
||||
" for (flatbuffers::uoffset_t i = 0; i < "
|
||||
"curr_{{FIELD_NAME}}->size(); i++) {";
|
||||
code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);";
|
||||
code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);";
|
||||
code_ += " if(lhs != rhs)";
|
||||
code_ +=
|
||||
" return static_cast<int>(lhs > rhs)"
|
||||
" - static_cast<int>(lhs < rhs);";
|
||||
code_ += " }";
|
||||
code_ += " return 0;";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user