Thrift: Slight tweaks to local reflection.
Summary:
Local reflection typespecs for structs now have a dummy T_STOP field at the end
so we don't have to check the size on every iteration.
They also contain information about which fields are optional.
Also put a static pointer to the reflection in each structure.
Reviewed By: mcslee
Test Plan: test/DenseLinkingTest.thrift
Revert Plan: ok
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665246 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/TReflectionLocal.h b/lib/cpp/src/TReflectionLocal.h
index 6f082e7..414a0eb 100644
--- a/lib/cpp/src/TReflectionLocal.h
+++ b/lib/cpp/src/TReflectionLocal.h
@@ -21,13 +21,21 @@
* @author David Reiss <dreiss@facebook.com>
*/
+struct FieldMeta {
+ int16_t tags;
+ bool is_optional;
+};
+
struct TypeSpec {
// Use an anonymous union here so we can fit two TypeSpecs in one cache line.
union {
struct {
// Use parallel arrays here for denser packing (of the arrays).
- int16_t* ftags;
+ FieldMeta* metas;
TypeSpec** specs;
+ // n_fields is only used for debugging, but it should only add
+ // a minimimal amount to the effective size of this structure
+ // because of alignment restrictions.
int n_fields;
} tstruct;
struct {
@@ -47,11 +55,11 @@
TypeSpec(TType ttype) : ttype(ttype) {}
- TypeSpec(TType ttype, int n_fields, int16_t* ftags, TypeSpec** specs) :
+ TypeSpec(TType ttype, int n_fields, FieldMeta* metas, TypeSpec** specs) :
ttype(ttype)
{
tstruct.n_fields = n_fields;
- tstruct.ftags = ftags;
+ tstruct.metas = metas;
tstruct.specs = specs;
}