diff options
author | Frank Benkstein <frank@benkstein.net> | 2018-10-15 21:26:35 +0200 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-10-15 12:26:35 -0700 |
commit | a3d8391f7be8c29660f77953f2fea11c76864408 (patch) | |
tree | 81f0b0d47c2d8e4c25bbb0b59c393897c293c33f /include/flatbuffers/idl.h | |
parent | 241e87d143516f1d885c5da8bb633a805833a31d (diff) | |
download | flatbuffers-a3d8391f7be8c29660f77953f2fea11c76864408.tar.gz |
don't use std::function in flatbuffers::Parser (#4995)
std::function makes code harder to debug because it requires stepping
through a separate destructor and call operator. It's use unnecessary
in the Parser since the functions taking functors are private and are
only used within idl_parser.cpp. Therefore the definitions can stay in
idl_parser.cpp as well. Only care must be taken that the definitions
appear before use but that's already true and all compilers will
complain equally if it get's violated. This change might also improve
performance since it might allow inlining where it wasn't possible
before but I haven't measured that.
Diffstat (limited to 'include/flatbuffers/idl.h')
-rw-r--r-- | include/flatbuffers/idl.h | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 024f324e..e1c75989 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -682,35 +682,15 @@ class Parser : public ParserState { FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field, size_t parent_fieldn, const StructDef *parent_struct_def); - // clang-format off - #if defined(FLATBUFFERS_CPP98_STL) - typedef CheckedError (*ParseTableDelimitersBody)( - const std::string &name, size_t &fieldn, const StructDef *struct_def, - void *state); - #else - typedef std::function<CheckedError(const std::string&, size_t&, - const StructDef*, void*)> - ParseTableDelimitersBody; - #endif // defined(FLATBUFFERS_CPP98_STL) - // clang-format on + template<typename F> FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn, const StructDef *struct_def, - ParseTableDelimitersBody body, - void *state); + F body); FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def, std::string *value, uoffset_t *ovalue); void SerializeStruct(const StructDef &struct_def, const Value &val); - // clang-format off - #if defined(FLATBUFFERS_CPP98_STL) - typedef CheckedError (*ParseVectorDelimitersBody)(size_t &count, - void *state); - #else - typedef std::function<CheckedError(size_t&, void*)> - ParseVectorDelimitersBody; - #endif // defined(FLATBUFFERS_CPP98_STL) - // clang-format on - FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters( - size_t &count, ParseVectorDelimitersBody body, void *state); + template<typename F> + FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(size_t &count, F body); FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue); FLATBUFFERS_CHECKED_ERROR ParseNestedFlatbuffer(Value &val, FieldDef *field, size_t fieldn, @@ -761,14 +741,7 @@ class Parser : public ParserState { Namespace *UniqueNamespace(Namespace *ns); FLATBUFFERS_CHECKED_ERROR RecurseError(); - template<typename F> CheckedError Recurse(F f) { - if (recurse_protection_counter >= (FLATBUFFERS_MAX_PARSING_DEPTH)) - return RecurseError(); - recurse_protection_counter++; - auto ce = f(); - recurse_protection_counter--; - return ce; - } + template<typename F> CheckedError Recurse(F f); public: SymbolTable<Type> types_; |