Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6d77c59 authored by Jeff Brown's avatar Jeff Brown
Browse files

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
parent 599ebfd4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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
+7 −0
Original line number Diff line number Diff line
@@ -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 };
};


// ---------------------------------------------------------------------------

/**
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <string.h>

#include <utils/StrongPointer.h>
#include <utils/TypeHelpers.h>

// ---------------------------------------------------------------------------
namespace android {
+3 −0
Original line number Diff line number Diff line
@@ -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...
+5 −0
Original line number Diff line number Diff line
@@ -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);

// ---------------------------------------------------------------------------
Loading