Avoid creating temporary objects in FiterValue().
It reduces the cpu time from 1000ns to 750ns
Test: statsd test.
Change-Id: Ifa7e98e3368f8d55f85c7b09d05a6c416482981d
diff --git a/cmds/statsd/src/FieldValue.h b/cmds/statsd/src/FieldValue.h
index d17dded..21f30e2 100644
--- a/cmds/statsd/src/FieldValue.h
+++ b/cmds/statsd/src/FieldValue.h
@@ -31,7 +31,7 @@
const int32_t kLastBitMask = 0x80;
const int32_t kClearLastBitDeco = 0x7f;
-enum Type { INT, LONG, FLOAT, STRING };
+enum Type { UNKNOWN, INT, LONG, FLOAT, STRING };
int32_t getEncodedField(int32_t pos[], int32_t depth, bool includeDepth);
@@ -82,6 +82,8 @@
int32_t mField;
public:
+ Field() {}
+
Field(int32_t tag, int32_t pos[], int32_t depth) : mTag(tag) {
mField = getEncodedField(pos, depth, true);
}
@@ -229,6 +231,8 @@
*
*/
struct Value {
+ Value() : type(UNKNOWN) {}
+
Value(int32_t v) {
int_value = v;
type = INT;
@@ -280,15 +284,13 @@
bool operator!=(const Value& that) const;
bool operator<(const Value& that) const;
-
-private:
- Value(){};
};
/**
* Represents a log item, or a dimension item (They are essentially the same).
*/
struct FieldValue {
+ FieldValue() {}
FieldValue(const Field& field, const Value& value) : mField(field), mValue(value) {
}
bool operator==(const FieldValue& that) const {