summaryrefslogtreecommitdiffstats
path: root/include/utils
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-03-16 14:45:49 -0700
committerJeff Brown <jeffbrown@google.com>2012-03-16 16:21:21 -0700
commite6d77c593d1a25b45c23bf9292ec7ee09fc14b6e (patch)
tree7246b3be522780008cf90a2ce112bd70c52e344d /include/utils
parent599ebfd48d43933e2edcfd4f18a0b1a9a9d7ff38 (diff)
downloadframeworks_native-e6d77c593d1a25b45c23bf9292ec7ee09fc14b6e.zip
frameworks_native-e6d77c593d1a25b45c23bf9292ec7ee09fc14b6e.tar.gz
frameworks_native-e6d77c593d1a25b45c23bf9292ec7ee09fc14b6e.tar.bz2
Add traits to common utils data structures.
Many of our basic data structures are trivially movable using memcpy() even if they are not trivially constructable, destructable or copyable. It's worth taking advantage of this *ahem* trait. Adding trivial_move_trait to String16 reduces appt running time on frameworks/base/core/res by 40%! Change-Id: I630a1a027e2d0ded96856e4ca042ea82906289fe
Diffstat (limited to 'include/utils')
-rw-r--r--include/utils/BitSet.h3
-rw-r--r--include/utils/KeyedVector.h7
-rw-r--r--include/utils/RefBase.h1
-rw-r--r--include/utils/SortedVector.h3
-rw-r--r--include/utils/String16.h5
-rw-r--r--include/utils/String8.h5
-rw-r--r--include/utils/TypeHelpers.h20
-rw-r--r--include/utils/Vector.h3
8 files changed, 43 insertions, 4 deletions
diff --git a/include/utils/BitSet.h b/include/utils/BitSet.h
index 9452e86..e189d0c 100644
--- a/include/utils/BitSet.h
+++ b/include/utils/BitSet.h
@@ -18,6 +18,7 @@
#define UTILS_BITSET_H
#include <stdint.h>
+#include <utils/TypeHelpers.h>
/*
* Contains some bit manipulation helpers.
@@ -102,6 +103,8 @@ struct BitSet32 {
inline bool operator!= (const BitSet32& other) const { return value != other.value; }
};
+ANDROID_BASIC_TYPES_TRAITS(BitSet32)
+
} // namespace android
#endif // UTILS_BITSET_H
diff --git a/include/utils/KeyedVector.h b/include/utils/KeyedVector.h
index 85535bd..20575ee 100644
--- a/include/utils/KeyedVector.h
+++ b/include/utils/KeyedVector.h
@@ -91,6 +91,13 @@ private:
SortedVector< key_value_pair_t<KEY, VALUE> > mVector;
};
+// KeyedVector<KEY, VALUE> can be trivially moved using memcpy() because its
+// underlying SortedVector can be trivially moved.
+template<typename KEY, typename VALUE> struct trait_trivial_move<KeyedVector<KEY, VALUE> > {
+ enum { value = trait_trivial_move<SortedVector< key_value_pair_t<KEY, VALUE> > >::value };
+};
+
+
// ---------------------------------------------------------------------------
/**
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index c7a9b78..99f5182 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -25,6 +25,7 @@
#include <string.h>
#include <utils/StrongPointer.h>
+#include <utils/TypeHelpers.h>
// ---------------------------------------------------------------------------
namespace android {
diff --git a/include/utils/SortedVector.h b/include/utils/SortedVector.h
index 0e98aeb..2445525 100644
--- a/include/utils/SortedVector.h
+++ b/include/utils/SortedVector.h
@@ -133,6 +133,9 @@ protected:
virtual int do_compare(const void* lhs, const void* rhs) const;
};
+// SortedVector<T> can be trivially moved using memcpy() because moving does not
+// require any change to the underlying SharedBuffer contents or reference count.
+template<typename T> struct trait_trivial_move<SortedVector<T> > { enum { value = true }; };
// ---------------------------------------------------------------------------
// No user serviceable parts from here...
diff --git a/include/utils/String16.h b/include/utils/String16.h
index 360f407..fe06c57 100644
--- a/include/utils/String16.h
+++ b/include/utils/String16.h
@@ -20,6 +20,7 @@
#include <utils/Errors.h>
#include <utils/SharedBuffer.h>
#include <utils/Unicode.h>
+#include <utils/TypeHelpers.h>
// ---------------------------------------------------------------------------
@@ -112,6 +113,10 @@ private:
const char16_t* mString;
};
+// String16 can be trivially moved using memcpy() because moving does not
+// require any change to the underlying SharedBuffer contents or reference count.
+ANDROID_TRIVIAL_MOVE_TRAIT(String16)
+
TextOutput& operator<<(TextOutput& to, const String16& val);
// ---------------------------------------------------------------------------
diff --git a/include/utils/String8.h b/include/utils/String8.h
index 4163697..335e7f1 100644
--- a/include/utils/String8.h
+++ b/include/utils/String8.h
@@ -20,6 +20,7 @@
#include <utils/Errors.h>
#include <utils/SharedBuffer.h>
#include <utils/Unicode.h>
+#include <utils/TypeHelpers.h>
#include <string.h> // for strcmp
#include <stdarg.h>
@@ -219,6 +220,10 @@ private:
const char* mString;
};
+// String8 can be trivially moved using memcpy() because moving does not
+// require any change to the underlying SharedBuffer contents or reference count.
+ANDROID_TRIVIAL_MOVE_TRAIT(String8)
+
TextOutput& operator<<(TextOutput& to, const String16& val);
// ---------------------------------------------------------------------------
diff --git a/include/utils/TypeHelpers.h b/include/utils/TypeHelpers.h
index 1f2c2d5..2bf33c3 100644
--- a/include/utils/TypeHelpers.h
+++ b/include/utils/TypeHelpers.h
@@ -68,12 +68,24 @@ struct aggregate_traits {
};
};
-#define ANDROID_BASIC_TYPES_TRAITS( T ) \
- template<> struct trait_trivial_ctor< T > { enum { value = true }; }; \
- template<> struct trait_trivial_dtor< T > { enum { value = true }; }; \
- template<> struct trait_trivial_copy< T > { enum { value = true }; }; \
+#define ANDROID_TRIVIAL_CTOR_TRAIT( T ) \
+ template<> struct trait_trivial_ctor< T > { enum { value = true }; };
+
+#define ANDROID_TRIVIAL_DTOR_TRAIT( T ) \
+ template<> struct trait_trivial_dtor< T > { enum { value = true }; };
+
+#define ANDROID_TRIVIAL_COPY_TRAIT( T ) \
+ template<> struct trait_trivial_copy< T > { enum { value = true }; };
+
+#define ANDROID_TRIVIAL_MOVE_TRAIT( T ) \
template<> struct trait_trivial_move< T > { enum { value = true }; };
+#define ANDROID_BASIC_TYPES_TRAITS( T ) \
+ ANDROID_TRIVIAL_CTOR_TRAIT( T ) \
+ ANDROID_TRIVIAL_DTOR_TRAIT( T ) \
+ ANDROID_TRIVIAL_COPY_TRAIT( T ) \
+ ANDROID_TRIVIAL_MOVE_TRAIT( T )
+
// ---------------------------------------------------------------------------
/*
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index 5b5296b..e39a5b7 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -201,6 +201,9 @@ protected:
virtual void do_move_backward(void* dest, const void* from, size_t num) const;
};
+// Vector<T> can be trivially moved using memcpy() because moving does not
+// require any change to the underlying SharedBuffer contents or reference count.
+template<typename T> struct trait_trivial_move<Vector<T> > { enum { value = true }; };
// ---------------------------------------------------------------------------
// No user serviceable parts from here...