Skip to content

Commit

Permalink
[Go] Generate imports with fixed order (#5340)
Browse files Browse the repository at this point in the history
* use fixed order for golang imports

* grumble
  • Loading branch information
iceboy233 authored and aardappel committed May 13, 2019
1 parent bff7ffb commit b56d60f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ struct Namespace {
size_t from_table; // Part of the namespace corresponds to a message/table.
};

inline bool operator<(const Namespace &a, const Namespace &b) {
size_t min_size = std::min(a.components.size(), b.components.size());
for (size_t i = 0; i < min_size; ++i) {
if (a.components[i] != b.components[i])
return a.components[i] < b.components[i];
}
return a.components.size() < b.components.size();
}

// Base class for all definition types (fields, structs_, enums_).
struct Definition {
Definition()
Expand Down
8 changes: 7 additions & 1 deletion src/idl_gen_go.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ class GoGenerator : public BaseGenerator {
private:
Namespace go_namespace_;
Namespace *cur_name_space_;
std::set<const Namespace*> tracked_imported_namespaces_;

struct NamespacePtrLess {
bool operator()(const Namespace *a, const Namespace *b) const {
return *a < *b;
}
};
std::set<const Namespace *, NamespacePtrLess> tracked_imported_namespaces_;

// Most field accessors need to retrieve and test the field offset first,
// this is the prefix code for that.
Expand Down

0 comments on commit b56d60f

Please sign in to comment.