From efb2476d01b2bcc62569c8748327754a836195c3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 21 May 2010 17:27:15 +0200 Subject: Optimize enum representation in binary streams For string-based enums use integer representation instead of string when storing in binary streams. --- xsd/cxx/tree/stream-extraction-source.cxx | 28 +++++++++++++++++++++-- xsd/cxx/tree/stream-insertion-source.cxx | 38 +++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) (limited to 'xsd/cxx') diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx index 0828c79..3fe1bf0 100644 --- a/xsd/cxx/tree/stream-extraction-source.cxx +++ b/xsd/cxx/tree/stream-extraction-source.cxx @@ -175,6 +175,20 @@ namespace CXX t.dispatch (e); } + Boolean enum_based (false); + if (string_based) + { + SemanticGraph::Enumeration* base_enum (0); + IsEnumBasedType t (base_enum); + t.dispatch (e); + + enum_based = (base_enum != 0); + } + + String value; + if (string_based) + value = evalue (e); + UnsignedLong n (0); Streams const& st (options.value ()); for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) @@ -188,8 +202,18 @@ namespace CXX inherits (e, inherits_base_); - os << " (s, f, c)" - << "{"; + if (string_based && !enum_based) + { + // Use copy c-tor to pass the flags and container. + // + os << " (" << endl; + inherits (e, inherits_base_); + os << " (_xsd_" << name << "_literals_[s.read_uint ()]), f, c)"; + } + else + os << " (s, f, c)"; + + os << "{"; if (string_based) os << "_xsd_" << name << "_convert ();"; diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx index 09faf71..99b3c74 100644 --- a/xsd/cxx/tree/stream-insertion-source.cxx +++ b/xsd/cxx/tree/stream-insertion-source.cxx @@ -168,6 +168,26 @@ namespace CXX if (renamed_type (e, name) && !name) return; + Boolean string_based (false); + { + IsStringBasedType t (string_based); + t.dispatch (e); + } + + Boolean enum_based (false); + if (string_based) + { + SemanticGraph::Enumeration* base_enum (0); + IsEnumBasedType t (base_enum); + t.dispatch (e); + + enum_based = (base_enum != 0); + } + + String value; + if (string_based) + value = evalue (e); + UnsignedLong n (0); Streams const& st (options.value ()); for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) @@ -177,13 +197,21 @@ namespace CXX os << stream_type << "&" << endl << "operator<< (" << stream_type << "& s," << endl << "const " << name << "& x)" - << "{" - << "return s << static_cast< const "; + << "{"; - inherits (e, inherits_base_); + if (!string_based || enum_based) + { + os << "return s << static_cast< const "; + inherits (e, inherits_base_); + os << "& > (x);"; + } + else + { + os << name << "::" << value << " v (x);" + << "return s << static_cast< unsigned int > (v);"; + } - os << "& > (x);" - << "}"; + os << "}"; // Register with type map. // -- cgit v1.1