Browse Source

Minor performance tweaks for love::Type

On my system these tweaks restore performance to "enum" levels

--HG--
branch : dynamiccore2
Bart van Strien 8 years ago
parent
commit
de29986d38
2 changed files with 21 additions and 21 deletions
  1. 3 16
      src/common/types.cpp
  2. 18 5
      src/common/types.h

+ 3 - 16
src/common/types.cpp

@@ -28,17 +28,18 @@ namespace love
 
 static std::unordered_map<std::string, Type*> types;
 
-uint32 love::Type::nextId = 1;
-
 Type::Type(const char *name, Type *parent)
 	: name(name)
 	, parent(parent)
+	, id(0)
 	, inited(false)
 {
 }
 
 void Type::init()
 {
+	static uint32 nextId = 1;
+
 	// Make sure we don't init twice, that would be bad
 	if (inited)
 		return;
@@ -63,20 +64,6 @@ uint32 Type::getId()
 	return id;
 }
 
-bool Type::isa(const uint32 &other)
-{
-	if (!inited)
-		init();
-	return bits[other];
-}
-
-bool Type::isa(love::Type &other)
-{
-	if (!other.inited)
-		other.init();
-	return isa(other.id);
-}
-
 const char *Type::getName() const
 {
 	return name;

+ 18 - 5
src/common/types.h

@@ -38,17 +38,30 @@ public:
 	Type(const char *name, Type *parent);
 	Type(const Type&) = delete;
 
+	static Type *byName(const char *name);
+
 	void init();
 	uint32 getId();
-	bool isa(const uint32 &other);
-	bool isa(Type &other);
 	const char *getName() const;
 
-	static Type *byName(const char *name);
+	bool isa(const uint32 &other)
+	{
+		if (!inited)
+			init();
+		return bits[other];
+	}
 
-private:
-	static uint32 nextId;
+	bool isa(Type &other)
+	{
+		if (!inited)
+			init();
+		// Note that if this type implements the other
+		// calling init above will also have inited
+		// the other.
+		return bits[other.id];
+	}
 
+private:
 	const char * const name;
 	Type * const parent;
 	uint32 id;