Selaa lähdekoodia

Removed a dynamic memory allocation while searching for a type in the RTTI factory & when creating a JobSystemThreadPool

Jorrit Rouwe 3 vuotta sitten
vanhempi
commit
11025e6dd1
3 muutettua tiedostoa jossa 6 lisäystä ja 8 poistoa
  1. 1 1
      Jolt/Core/Factory.h
  2. 4 6
      Jolt/Core/JobSystemThreadPool.cpp
  3. 1 1
      Jolt/Core/JobSystemThreadPool.h

+ 1 - 1
Jolt/Core/Factory.h

@@ -34,7 +34,7 @@ public:
 	static Factory 				sInstance;
 
 private:
-	using ClassNameMap = unordered_map<string, const RTTI *>;
+	using ClassNameMap = unordered_map<string_view, const RTTI *>;
 
 	using ClassHashMap = unordered_map<uint32, const RTTI *>;
 

+ 4 - 6
Jolt/Core/JobSystemThreadPool.cpp

@@ -267,10 +267,8 @@ void JobSystemThreadPool::StartThreads(int inNumThreads)
 	for (int i = 0; i < inNumThreads; ++i)
 	{
 		// Name the thread
-		stringstream namestream;
-		namestream << "Worker ";
-		namestream << (i + 1);
-		string name = namestream.str();
+		char name[64];
+		snprintf(name, sizeof(name), "Worker %d", int(i + 1));
 
 		// Create thread
 		mThreads.emplace_back([this, name, i] { ThreadMain(name, i); });
@@ -516,10 +514,10 @@ static void SetThreadName(const char *inName)
 
 #endif
 
-void JobSystemThreadPool::ThreadMain([[maybe_unused]] const string &inName, int inThreadIndex)
+void JobSystemThreadPool::ThreadMain([[maybe_unused]] const char *inName, int inThreadIndex)
 {
 #ifdef JPH_PLATFORM_WINDOWS
-	SetThreadName(inName.c_str());
+	SetThreadName(inName);
 #endif
 
 	// Enable floating point exceptions

+ 1 - 1
Jolt/Core/JobSystemThreadPool.h

@@ -115,7 +115,7 @@ private:
 	void					StopThreads();
 	
 	/// Entry point for a thread
-	void					ThreadMain(const string &inName, int inThreadIndex);
+	void					ThreadMain(const char *inName, int inThreadIndex);
 
 	/// Get the head of the thread that has processed the least amount of jobs
 	inline uint				GetHead() const;