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

Requested reviews:
  Markos Zaharioudakis (markos-za)

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

More types-related optimizations for the comparison operators
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/89863
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
--- src/runtime/booleans/BooleanImpl.cpp	2012-01-11 16:30:06 +0000
+++ src/runtime/booleans/BooleanImpl.cpp	2012-01-24 11:27:35 +0000
@@ -821,22 +821,22 @@
 ********************************************************************************/
 bool CompareIterator::equal(
     const QueryLoc& loc,
-    const store::Item_t& aItem0,
-    const store::Item_t& aItem1,
+    const store::Item_t& item0,
+    const store::Item_t& item1,
     const TypeManager* tm,
     long timezone,
-    XQPCollator* aCollation)
+    XQPCollator* collation)
 {
-  xqtref_t type0 = tm->create_value_type(aItem0.getp());
-  xqtref_t type1 = tm->create_value_type(aItem1.getp());
+  store::SchemaTypeCode type0 = item0->getTypeCode();
+  store::SchemaTypeCode type1 = item1->getTypeCode();
 
-  if (TypeOps::is_subtype(tm, *type0, *type1))
+  if (TypeOps::is_subtype(type0, type1))
   {
-    return aItem1->equals(aItem0, timezone, aCollation);
+    return item1->equals(item0, timezone, collation);
   }
-  else if (TypeOps::is_subtype(tm, *type1, *type0))
+  else if (TypeOps::is_subtype(type1, type0))
   {
-    return aItem0->equals(aItem1, timezone, aCollation);
+    return item0->equals(item1, timezone, collation);
   }
   else
   {
@@ -847,23 +847,26 @@
     // xs::duration (i.e. one is xs:yearMonthDuration and the other is
     // xs:dayTimeDuration).
     // The same case happens when there are two types derived from xs:NOTATION.
-    if (TypeOps::is_subtype(tm, *type0, *GENV_TYPESYSTEM.INTEGER_TYPE_ONE) &&
-        TypeOps::is_subtype(tm, *type1, *GENV_TYPESYSTEM.INTEGER_TYPE_ONE))
-    {
-      return (aItem0->getIntegerValue() == aItem1->getIntegerValue());
-    }
-    else if (TypeOps::is_subtype(tm, *type0, *GENV_TYPESYSTEM.DURATION_TYPE_ONE) &&
-             TypeOps::is_subtype(tm, *type1, *GENV_TYPESYSTEM.DURATION_TYPE_ONE))
-    {
-      return (aItem0->getDurationValue() == aItem1->getDurationValue());
-    }
-    else if (TypeOps::is_subtype(tm, *type0, *GENV_TYPESYSTEM.NOTATION_TYPE_ONE) &&
-             TypeOps::is_subtype(tm, *type1, *GENV_TYPESYSTEM.NOTATION_TYPE_ONE))
-    {
-      return aItem0->equals(aItem1);
+    if (TypeOps::is_subtype(type0, store::XS_INTEGER) &&
+        TypeOps::is_subtype(type1, store::XS_INTEGER))
+    {
+      return (item0->getIntegerValue() == item1->getIntegerValue());
+    }
+    else if (TypeOps::is_subtype(type0, store::XS_DURATION) &&
+             TypeOps::is_subtype(type1, store::XS_DURATION))
+    {
+      return (item0->getDurationValue() == item1->getDurationValue());
+    }
+    else if (TypeOps::is_subtype(type0, store::XS_NOTATION) &&
+             TypeOps::is_subtype(type1, store::XS_NOTATION))
+    {
+      return item0->equals(item1);
     }
     else
     {
+      xqtref_t type0 = tm->create_value_type(item0.getp());
+      xqtref_t type1 = tm->create_value_type(item1.getp());
+
       RAISE_ERROR(err::XPTY0004, loc,
       ERROR_PARAMS(ZED(BadType_23o), *type0, ZED(NoCompareWithType_4), *type1));
     }
@@ -890,51 +893,56 @@
 ********************************************************************************/
 long CompareIterator::compare(
     const QueryLoc& loc,
-    const store::Item_t& aItem0,
-    const store::Item_t& aItem1,
+    const store::Item_t& item0,
+    const store::Item_t& item1,
     const TypeManager* tm,
     long timezone,
-    XQPCollator* aCollation)
+    XQPCollator* collation)
 {
-  xqtref_t type0 = tm->create_value_type(aItem0.getp());
-  xqtref_t type1 = tm->create_value_type(aItem1.getp());
+  store::SchemaTypeCode type0 = item0->getTypeCode();
+  store::SchemaTypeCode type1 = item1->getTypeCode();
 
   try
   {
-    if (TypeOps::is_subtype(tm, *type0, *GENV_TYPESYSTEM.DURATION_TYPE_ONE) &&
-        TypeOps::is_subtype(tm, *type1, *GENV_TYPESYSTEM.DURATION_TYPE_ONE))
+    if (TypeOps::is_subtype(type0, store::XS_DURATION) &&
+        TypeOps::is_subtype(type1, store::XS_DURATION))
     {
-      if (TypeOps::is_equal(tm, *type0, *type1) &&
-          !TypeOps::is_equal(tm, *type0, *GENV_TYPESYSTEM.DURATION_TYPE_ONE))
+      if (type0 == type1 && type0 != store::XS_DURATION)
       {
-        return aItem0->compare(aItem1, timezone, aCollation);
+        return item0->compare(item1, timezone, collation);
       }
       else
       {
+        xqtref_t type0 = tm->create_value_type(item0.getp());
+        xqtref_t type1 = tm->create_value_type(item1.getp());
+
         RAISE_ERROR(err::XPTY0004, loc,
         ERROR_PARAMS(ZED(BadType_23o), *type0, ZED(NoCompareWithType_4), *type1));
       }
     }
-    else if (TypeOps::is_subtype(tm, *type1, *type0))
+    else if (TypeOps::is_subtype(type1, type0))
     {
-      return aItem0->compare(aItem1, timezone, aCollation);
+      return item0->compare(item1, timezone, collation);
     }
-    else if (TypeOps::is_subtype(tm, *type0, *type1))
+    else if (TypeOps::is_subtype(type0, type1))
     {
-      return -aItem1->compare(aItem0, timezone, aCollation);
+      return -item1->compare(item0, timezone, collation);
     }
     else
     {
       // There is 1 case when two types are order-comparable without one being a
       // subtype of the other: they belong to different branches under of the
       // type-inheritance subtree rooted at xs:Integer.
-      if (TypeOps::is_subtype(tm, *type0, *GENV_TYPESYSTEM.INTEGER_TYPE_ONE) &&
-          TypeOps::is_subtype(tm, *type1, *GENV_TYPESYSTEM.INTEGER_TYPE_ONE))
+      if (TypeOps::is_subtype(type0, store::XS_INTEGER) &&
+          TypeOps::is_subtype(type1, store::XS_INTEGER))
       {
-        return aItem0->getIntegerValue().compare( aItem1->getIntegerValue() );
+        return item0->getIntegerValue().compare(item1->getIntegerValue());
       }
       else
       {
+        xqtref_t type0 = tm->create_value_type(item0.getp());
+        xqtref_t type1 = tm->create_value_type(item1.getp());
+
         RAISE_ERROR(err::XPTY0004, loc,
         ERROR_PARAMS(ZED(BadType_23o), *type0, ZED(NoCompareWithType_4), *type1));
       }
@@ -945,6 +953,9 @@
     // For example, two QName items do not have an order relationship.
     if (e.diagnostic() == zerr::ZSTR0040_TYPE_ERROR)
     {
+      xqtref_t type0 = tm->create_value_type(item0.getp());
+      xqtref_t type1 = tm->create_value_type(item1.getp());
+
       RAISE_ERROR(err::XPTY0004, loc,
       ERROR_PARAMS(ZED(BadType_23o), *type0, ZED(NoCompareWithType_4), *type1));
     }

=== modified file 'src/store/naive/qname_pool.cpp'
--- src/store/naive/qname_pool.cpp	2011-10-03 09:18:49 +0000
+++ src/store/naive/qname_pool.cpp	2012-01-24 11:27:35 +0000
@@ -63,8 +63,8 @@
 ********************************************************************************/
 QNamePool::~QNamePool() 
 {
-  ulong n = (ulong)theHashSet.theHashTab.size();
-  for (ulong i = 0; i < n; i++)
+  csize n = theHashSet.theHashTab.size();
+  for (csize i = 0; i < n; ++i)
   {
     if (!theHashSet.theHashTab[i].isFree())
     {

=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp	2012-01-11 10:30:49 +0000
+++ src/types/casting.cpp	2012-01-24 11:27:35 +0000
@@ -1340,7 +1340,6 @@
 bool str_down(
     store::Item_t& result,
     const store::Item* aItem,
-    RootTypeManager& aTS,
     ATOMIC_CODE_T aTargetAtomicType,
     store::ItemFactory* aFactory,
     const ErrorInfo& aErrorInfo)
@@ -1432,7 +1431,6 @@
 bool int_down(
     store::Item_t& result,
     const store::Item* aItem,
-    RootTypeManager& aTS,
     ATOMIC_CODE_T aTargetAtomicType,
     store::ItemFactory* aFactory,
     const ErrorInfo& aErrorInfo)
@@ -1457,11 +1455,13 @@
   {
     zstring lString;
     aItem->getStringValue2(lString);
-    try {
+    try 
+    {
       xs_long const n = ztd::aton<xs_long>(lString.c_str());
       return aFactory->createLong(result, n);
     }
-    catch ( std::exception const& ) {
+    catch ( std::exception const& ) 
+    {
       // ignore
     }
     break;
@@ -1470,11 +1470,13 @@
   {
     zstring lString;
     aItem->getStringValue2(lString);
-    try {
+    try 
+    {
       xs_int const n = ztd::aton<xs_int>(lString.c_str());
       return aFactory->createInt(result, n);
     }
-    catch ( std::exception const& ) {
+    catch ( std::exception const& ) 
+    {
       // ignore
     }
     break;
@@ -1483,11 +1485,13 @@
   {
     zstring lString;
     aItem->getStringValue2(lString);
-    try {
+    try 
+    {
       xs_short const n = ztd::aton<xs_short>(lString.c_str());
       return aFactory->createShort(result, n);
     }
-    catch ( std::exception const& ) {
+    catch ( std::exception const& ) 
+    {
       // ignore
     }
     break;
@@ -1529,11 +1533,13 @@
   {
     zstring lString;
     aItem->getStringValue2(lString);
-    try {
+    try 
+    {
       xs_unsignedInt const n = ztd::aton<xs_unsignedInt>(lString.c_str());
       return aFactory->createUnsignedInt(result, n);
     }
-    catch ( std::exception const& ) {
+    catch ( std::exception const& ) 
+    {
       // ignore
     }
     break;
@@ -1542,11 +1548,13 @@
   {
     zstring lString;
     aItem->getStringValue2(lString);
-    try {
+    try 
+    {
       xs_unsignedShort const n = ztd::aton<xs_unsignedShort>(lString.c_str());
       return aFactory->createUnsignedShort(result, n);
     }
-    catch ( std::exception const& ) {
+    catch ( std::exception const& ) 
+    {
       // ignore
     }
     break;
@@ -1555,11 +1563,13 @@
   {
     zstring lString;
     aItem->getStringValue2(lString);
-    try {
+    try 
+    {
       xs_unsignedByte const n = ztd::aton<xs_unsignedByte>(lString.c_str());
       return aFactory->createUnsignedByte(result, n);
     }
-    catch ( std::exception const& ) {
+    catch ( std::exception const& ) 
+    {
       // ignore
     }
     break;
@@ -1818,7 +1828,6 @@
   {
     valid = (*lDownCastFunc)(result,
                              &*result,
-                             rtm,
                              targetTypeCode,
                              lFactory,
                              lErrorInfo);
@@ -1842,7 +1851,6 @@
     namespace_context*   nsCtx,
     const QueryLoc&      loc)
 {
-  RootTypeManager& rtm = GENV_TYPESYSTEM;
   store::ItemFactory* factory = GENV_ITEMFACTORY;
 
   ZORBA_ASSERT(aItem->isAtomic());
@@ -1925,7 +1933,6 @@
   {
     valid = (*downCastFunc)(result,
                             &*result,
-                            rtm,
                             targetTypeCode,
                             factory,
                             errorInfo);
@@ -1950,22 +1957,19 @@
     namespace_context*    nsCtx,
     const QueryLoc&       loc)
 {
-  RootTypeManager& rtm = GENV_TYPESYSTEM;
   store::ItemFactory* factory = GENV_ITEMFACTORY;
   zstring sourceString;
 
-  ZORBA_ASSERT(item->isAtomic());
-
   store::SchemaTypeCode sourceType = item->getTypeCode();
 
+  if (sourceType == targetType)
+  {
+    result.transfer(item);
+    return true;
+  }
+
   ErrorInfo errorInfo(sourceType, targetType, loc);
 
-  if (sourceType == targetType)
-  {
-    result.transfer(item);
-    return true;
-  }
-
   if (targetType == store::XS_NOTATION ||
       targetType == store::XS_ANY_ATOMIC)
   {
@@ -1973,18 +1977,24 @@
   }
 
   if (sourceType == store::XS_ANY_ATOMIC)
+  {
     throwTypeException(err::XPTY0004, errorInfo);
+  }
 
   if (targetType == store::XS_NCNAME &&
       sourceType != store::XS_STRING &&
       sourceType != store::XS_NCNAME &&
       sourceType != store::XS_UNTYPED_ATOMIC)
+  {
     throwTypeException(err::XPTY0004, errorInfo);
+  }
 
   CastFunc castFunc = theCastMatrix[theMapping[sourceType]]
                                     [theMapping[targetType]];
   if (castFunc == 0)
+  {
     throwTypeException(err::XPTY0004, errorInfo);
+  }
 
   if (theMapping[sourceType] == theMapping[store::XS_STRING])
   {
@@ -2006,7 +2016,6 @@
   {
     valid = (*downCastFunc)(result,
                             &*result,
-                            rtm,
                             targetType,
                             factory,
                             errorInfo);

=== modified file 'src/types/casting.h'
--- src/types/casting.h	2012-01-11 10:30:49 +0000
+++ src/types/casting.h	2012-01-24 11:27:35 +0000
@@ -40,16 +40,15 @@
                             zstring& strval,
                             store::ItemFactory*, 
                             namespace_context *nsCtx,
-                            const ErrorInfo& aErrorInfo
-                        );
+                            const ErrorInfo& aErrorInfo);
+
   typedef bool (*DownCastFunc)(
                             store::Item_t&,
                             const store::Item*, 
-                            RootTypeManager& aTS,
                             store::SchemaTypeCode aTargetAtomicType,
                             store::ItemFactory*,
-                            const ErrorInfo& aErrorInfo
-                        ); 
+                            const ErrorInfo& aErrorInfo);
+ 
 private:
   static const int          theMapping[store::XS_LAST];
   static const CastFunc     theCastMatrix[23][23];

-- 
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