Changeset 19631 in webkit


Ignore:
Timestamp:
Feb 14, 2007, 3:42:44 PM (18 years ago)
Author:
andersca
Message:

Reviewed by Darin.

Add new canCompareWithMemcmp vector trait and use it to determine whether
operator== can use memcmp.


  • wtf/Vector.h: (WTF::): (WTF::VectorTypeOperations::compare): (WTF::operator==):
  • wtf/VectorTraits.h: (WTF::):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r19613 r19631  
     12007-02-14  Anders Carlsson  <acarlsson@apple.com>
     2
     3        Reviewed by Darin.
     4
     5        Add new canCompareWithMemcmp vector trait and use it to determine whether
     6        operator== can use memcmp.
     7       
     8        * wtf/Vector.h:
     9        (WTF::):
     10        (WTF::VectorTypeOperations::compare):
     11        (WTF::operator==):
     12        * wtf/VectorTraits.h:
     13        (WTF::):
     14
    1152007-02-13  Brady Eidson  <beidson@apple.com>
    216
  • trunk/JavaScriptCore/wtf/Vector.h

    r19613 r19631  
    177177    };
    178178   
     179    template<bool canCompareWithMemcmp, typename T>
     180    class VectorComparer;
     181   
     182    template<typename T>
     183    struct VectorComparer<false, T>
     184    {
     185        static bool compare(const T* a, const T* b, size_t size)
     186        {
     187            for (size_t i = 0; i < size; ++i)
     188                if (a[i] != b[i])
     189                    return false;
     190            return false;
     191        }
     192    };
     193
     194    template<typename T>
     195    struct VectorComparer<true, T>
     196    {
     197        static bool compare(const T* a, const T* b, size_t size)
     198        {
     199            return memcmp(a, b, sizeof(T) * size) == 0;
     200        }
     201    };
     202   
    179203    template<typename T>
    180204    struct VectorTypeOperations
     
    208232        {
    209233            VectorFiller<VectorTraits<T>::canFillWithMemset, T>::uninitializedFill(dst, dstEnd, val);
     234        }
     235       
     236        static bool compare(const T* a, const T* b, size_t size)
     237        {
     238            return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::compare(a, b, size);
    210239        }
    211240    };
     
    669698            return false;
    670699
    671         for (size_t i = 0; i < a.size(); ++i)
    672             if (a.at(i) != b.at(i))
    673                 return false;
    674 
    675         return true;
     700        return VectorTypeOperations<T>::compare(a.data(), b.data(), a.size());
    676701    }
    677702
  • trunk/JavaScriptCore/wtf/VectorTraits.h

    r17127 r19631  
    6161        static const bool canCopyWithMemcpy = false;
    6262        static const bool canFillWithMemset = false;
     63        static const bool canCompareWithMemcmp = false;
    6364    };
    6465
     
    7273        static const bool canCopyWithMemcpy = true;
    7374        static const bool canFillWithMemset = sizeof(T) == sizeof(char);
     75        static const bool canCompareWithMemcmp = true;
    7476    };
    7577
     
    8587        static const bool canCopyWithMemcpy = false;
    8688        static const bool canFillWithMemset = false;
     89        static const bool canCompareWithMemcmp = true;
    8790    };
    8891
     
    104107        static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && SecondTraits::canCopyWithMemcpy;
    105108        static const bool canFillWithMemset = false;
     109        static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp;
    106110    };
    107111
Note: See TracChangeset for help on using the changeset viewer.