Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch 
into lp:zorba.

Commit message:
Inlined Item::getTypeCode method for better performance

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/157572

Inlined Item::getTypeCode method for better performance
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/157572
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/expression/path_expr.h'
--- src/compiler/expression/path_expr.h	2013-02-07 17:24:36 +0000
+++ src/compiler/expression/path_expr.h	2013-04-08 00:46:23 +0000
@@ -22,6 +22,7 @@
 
 #include "zorbatypes/zstring.h"
 
+#include <zorba/store_consts.h>
 
 namespace zorba
 {

=== modified file 'src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp	2013-03-22 00:38:18 +0000
+++ src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp	2013-04-08 00:46:23 +0000
@@ -48,6 +48,48 @@
 
 class ParseNodePrintXQDocVisitor : public parsenode_visitor
 {
+protected:
+  store::Item_t&       theResult;
+
+  store::Item_t        theModule;
+  store::Item_t        theImports;
+  store::Item_t        theVariables;
+  store::Item_t        theFunctions;
+  store::Item_t        theCollections;
+  store::Item_t        theIndexes;
+
+  // set of functions being invoked in the function
+  // whoes declaration is currently being processed
+  map<string, store::Item_t>  theInvokedFunc;
+
+  // prefix -> uri
+  map<zstring, zstring> theNamespaceMap;
+
+  // prefix -> uri for the schema imports
+  map<zstring, zstring> theNamespaceSchemaMap;
+
+  const char*          theXQDocNS;
+  const char*          theXQDocPrefix;
+
+  zstring              theFileName;
+  zstring              theBaseURI;
+  zstring              theVersion;
+  store::NsBindings    theNSBindings;
+
+  store::ItemFactory * theFactory;
+
+  string               theQuery;
+  zstring              theEncoding;
+  zstring              theXQueryVersion;
+
+  uint32_t             theOptions;
+
+  // helper vars to compute index sources
+  bool                 theIsIndexDecl;
+  bool                 theWaitForIndexSourceLiteral;
+  std::vector<pair<zstring,zstring> > theIndexSources;
+
+
 private:
 
 string getFileName(const string& aFileName)
@@ -458,48 +500,6 @@
 }
 
 
-protected:
-  store::Item_t&       theResult;
-
-  store::Item_t        theModule;
-  store::Item_t        theImports;
-  store::Item_t        theVariables;
-  store::Item_t        theFunctions;
-  store::Item_t        theCollections;
-  store::Item_t        theIndexes;
-
-  // set of functions being invoked in the function
-  // whoes declaration is currently being processed
-  map<string, store::Item_t>  theInvokedFunc;
-
-  // prefix -> uri
-  map<zstring, zstring> theNamespaceMap;
-
-  // prefix -> uri for the schema imports
-  map<zstring, zstring> theNamespaceSchemaMap;
-
-  const char*          theXQDocNS;
-  const char*          theXQDocPrefix;
-
-  zstring              theFileName;
-  zstring              theBaseURI;
-  zstring              theVersion;
-  store::NsBindings    theNSBindings;
-
-  store::ItemFactory * theFactory;
-
-  string               theQuery;
-  zstring              theEncoding;
-  zstring              theXQueryVersion;
-
-  uint32_t             theOptions;
-
-  // helper vars to compute index sources
-  bool                 theIsIndexDecl;
-  bool                 theWaitForIndexSourceLiteral;
-  std::vector<pair<zstring,zstring> >
-                       theIndexSources;
-
 public:
 
 ParseNodePrintXQDocVisitor(store::Item_t& aResult,

=== modified file 'src/diagnostics/diagnostic.h'
--- src/diagnostics/diagnostic.h	2013-02-07 17:24:36 +0000
+++ src/diagnostics/diagnostic.h	2013-04-08 00:46:23 +0000
@@ -22,7 +22,7 @@
 #include <zorba/xquery_exception.h>
 
 #include "compiler/parser/query_loc.h"
-#include "store/api/item.h"
+#include "store/api/shared_types.h"
 
 namespace zorba {
 namespace diagnostic {
@@ -30,25 +30,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 /**
- * Given a store::Item_t that represents a QName, creates an instance of
- * QNameType having the same QName.
- *
- * @tparam QNameType The type of QName to create.
- * @param qname The QName item.
- * @return Returns said QNameType.
- */
-template<class QNameType> inline
-QNameType to_QName( store::Item_t const &qname ) {
-  return QNameType(
-    qname->getNamespace().c_str(),
-    qname->getPrefix().c_str(),
-    qname->getLocalName().c_str()
-  );
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-/**
  * Makes an empty location.
  *
  * @return Returns said location.

=== added file 'src/diagnostics/qname.h'
--- src/diagnostics/qname.h	1970-01-01 00:00:00 +0000
+++ src/diagnostics/qname.h	2013-04-08 00:46:23 +0000
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ZORBA_DIAGNOSTIC_QNAME_H
+#define ZORBA_DIAGNOSTIC_QNAME_H
+
+#include <zorba/config.h>
+
+#include "store/api/item.h"
+
+namespace zorba {
+namespace diagnostic {
+
+
+template<class QNameType>
+QNameType to_QName( store::Item_t const &qname ) {
+  return QNameType(
+    qname->getNamespace().c_str(),
+    qname->getPrefix().c_str(),
+    qname->getLocalName().c_str()
+  );
+}
+
+
+} // namespace diagnostic
+} // namespace zorba
+
+#endif /* ZORBA_DIAGNOSTIC_QNAME_H */
+/*
+ * Local variables:
+ * mode: c++
+ * End:
+ */
+/* vim:set et sw=2 ts=2: */

=== modified file 'src/diagnostics/xquery_stack_trace.cpp'
--- src/diagnostics/xquery_stack_trace.cpp	2013-02-07 17:24:36 +0000
+++ src/diagnostics/xquery_stack_trace.cpp	2013-04-08 00:46:23 +0000
@@ -25,6 +25,7 @@
 #include <zorba/xquery_exception.h>
 
 #include "diagnostic.h"
+#include "qname.h"
 
 namespace zorba {
 

=== modified file 'src/store/api/item.h'
--- src/store/api/item.h	2013-03-24 20:40:03 +0000
+++ src/store/api/item.h	2013-04-08 00:46:23 +0000
@@ -29,6 +29,8 @@
 #include <zorba/store_consts.h>
 #include "store/api/shared_types.h"
 
+#include "diagnostics/xquery_diagnostics.h"
+
 #ifndef ZORBA_NO_FULL_TEXT
 #include <zorba/locale.h>
 #include <zorba/tokenizer.h>
@@ -120,6 +122,7 @@
   void removeReference();
 
   virtual size_t alloc_size() const;
+
   virtual size_t dynamic_size() const;
 
   /* -------------------   General Methods for Items ------------------------- */
@@ -331,7 +334,17 @@
   /**
    * @return The numeric code coresponding to the data type of this item.
    */
-  SchemaTypeCode getTypeCode() const;
+  SchemaTypeCode getTypeCode() const
+  {
+    if (isAtomic())
+    {
+      return static_cast<SchemaTypeCode>(theUnion.itemKind >> 4);
+    }
+
+    throw ZORBA_EXCEPTION(
+    zerr::ZSTR0050_FUNCTION_NOT_IMPLEMENTED_FOR_ITEMTYPE,
+    ERROR_PARAMS(__FUNCTION__, typeid(*this).name()));
+  }
 
   /**
    * @return If this is an atomic item with a user-defined data type UT, return

=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp	2013-03-21 18:22:40 +0000
+++ src/store/naive/atomic_items.cpp	2013-04-08 00:46:23 +0000
@@ -2745,31 +2745,19 @@
 }
 
 
-long IntegerItemImpl::compare( Item const *other, long,
-                               const XQPCollator* ) const {
-  try
-  {
-    return theValue.compare( other->getIntegerValue() );
-  }
-  catch ( ZorbaException const& )
-  {
-    return getDecimalValue().compare( other->getDecimalValue() );
-  }
-}
-
-bool IntegerItemImpl::equals( const store::Item* other, long,
-                              const XQPCollator*) const
+long IntegerItemImpl::compare(Item const* other, long, const XQPCollator*) const
 {
   try
   {
-    return theValue == other->getIntegerValue();
+    return theValue.compare(other->getIntegerValue());
   }
-  catch (ZorbaException const&)
+  catch (ZorbaException const& )
   {
-    return getDecimalValue() == other->getDecimalValue();
+    return getDecimalValue().compare(other->getDecimalValue());
   }
 }
 
+
 xs_decimal IntegerItemImpl::getDecimalValue() const
 {
   return xs_decimal(theValue);
@@ -2870,20 +2858,24 @@
   return sizeof( *this );
 }
 
-long NonPositiveIntegerItem::compare( Item const *other, long,
-                                      const XQPCollator* ) const {
+
+long NonPositiveIntegerItem::compare(Item const* other, long, const XQPCollator*) const
+{
   try
   {
-    return theValue.compare( other->getIntegerValue() );
+    return theValue.compare(other->getIntegerValue());
   }
-  catch ( ZorbaException const& )
+  catch (ZorbaException const&)
   {
-    return getDecimalValue().compare( other->getDecimalValue() );
+    return getDecimalValue().compare(other->getDecimalValue());
   }
 }
 
-bool NonPositiveIntegerItem::equals( const store::Item* other, long,
-                                     const XQPCollator* ) const
+
+bool NonPositiveIntegerItem::equals(
+    const store::Item* other,
+    long,
+    const XQPCollator* ) const
 {
   try
   {
@@ -2895,21 +2887,25 @@
   }
 }
 
+
 store::Item* NonPositiveIntegerItem::getType() const
 {
   return GET_STORE().theSchemaTypeNames[store::XS_NON_POSITIVE_INTEGER];
 }
 
+
 xs_decimal NonPositiveIntegerItem::getDecimalValue() const
 {
   return xs_decimal(theValue);
 }
 
+
 xs_integer NonPositiveIntegerItem::getIntegerValue() const
 {
   return xs_integer(theValue);
 }
 
+
 xs_long NonPositiveIntegerItem::getLongValue() const
 {
   try

=== modified file 'src/store/naive/atomic_items.h'
--- src/store/naive/atomic_items.h	2013-03-21 18:22:40 +0000
+++ src/store/naive/atomic_items.h	2013-04-08 00:46:23 +0000
@@ -1566,17 +1566,26 @@
 
   store::Item* getType() const;
 
-  uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const;
-
-  long compare(
-        const Item* other,
-        long timezone = 0,
-        const XQPCollator* aCollation = 0) const;
-
-  bool equals(
-        const store::Item* other,
-        long timezone = 0,
-        const XQPCollator* aCollation = 0) const;
+  uint32_t hash(long = 0, const XQPCollator* c = 0) const;
+
+  long compare(const Item* other, long tz = 0, const XQPCollator* c = 0) const;
+
+  bool equals(const Item* other, long tz = 0, const XQPCollator* c = 0) const
+  {
+    try
+    {
+      if (other->getTypeCode() == store::XS_INTEGER)
+      {
+        return theValue == static_cast<const IntegerItemImpl*>(other)->theValue;
+      }
+
+      return theValue == other->getIntegerValue();
+    }
+    catch (ZorbaException const&)
+    {
+      return getDecimalValue() == other->getDecimalValue();
+    }
+  }
 
   bool getEBV() const;
 

=== modified file 'src/store/naive/item.cpp'
--- src/store/naive/item.cpp	2013-03-26 23:32:03 +0000
+++ src/store/naive/item.cpp	2013-04-08 00:46:23 +0000
@@ -220,7 +220,6 @@
     ZORBA_ASSERT(false);
   }
   }
-
 #endif
 }
 
@@ -289,19 +288,6 @@
 }
 
 
-store::SchemaTypeCode Item::getTypeCode() const
-{
-  if (isAtomic())
-  {
-    return static_cast<SchemaTypeCode>(theUnion.itemKind >> 4);
-  }
-
-  throw ZORBA_EXCEPTION(
-    zerr::ZSTR0050_FUNCTION_NOT_IMPLEMENTED_FOR_ITEMTYPE,
-    ERROR_PARAMS(__FUNCTION__, typeid(*this).name()));
-}
-
-
 Item* Item::getType() const
 {
   throw ZORBA_EXCEPTION(
@@ -318,10 +304,7 @@
 };
 
 
-bool Item::equals(
-    const store::Item* other,
-    long timezone,
-    const XQPCollator* aCollation) const
+bool Item::equals(const store::Item* other, long tz, const XQPCollator* c) const
 {
   throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR,
   ERROR_PARAMS(ZED(NoCompareTypes_23),

=== modified file 'src/zorbaserialization/serialize_basic_types.cpp'
--- src/zorbaserialization/serialize_basic_types.cpp	2013-02-07 17:24:36 +0000
+++ src/zorbaserialization/serialize_basic_types.cpp	2013-04-08 00:46:23 +0000
@@ -22,6 +22,8 @@
 #include "zorbaserialization/archiver.h"
 #include "zorbaserialization/base64impl.h"
 
+#include "zorbatypes/floatimpl.h"
+
 #include "diagnostics/xquery_diagnostics.h"
 #include "diagnostics/util_macros.h"
 #include "diagnostics/assert.h"

=== modified file 'src/zorbaserialization/serialize_template_types.h'
--- src/zorbaserialization/serialize_template_types.h	2013-03-04 21:00:58 +0000
+++ src/zorbaserialization/serialize_template_types.h	2013-04-08 00:46:23 +0000
@@ -32,6 +32,7 @@
 #include "diagnostics/assert.h"
 
 #include "zorbatypes/zstring.h"
+#include "zorbatypes/floatimpl.h"
 
 #include "zorbautils/checked_vector.h"
 

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to