Changeset 19631 in webkit for trunk/JavaScriptCore/wtf/Vector.h


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::):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.