Procházet zdrojové kódy

resource: replace Map with HashMap

Daniele Bartolini před 6 roky
rodič
revize
01d9c80686

+ 0 - 9
src/core/filesystem/file_monitor_linux.cpp

@@ -22,15 +22,6 @@
 
 namespace crown
 {
-template <>
-struct hash<DynamicString>
-{
-	u32 operator()(const DynamicString& str) const
-	{
-		return str.to_string_id()._id;
-	}
-};
-
 struct FileMonitorImpl
 {
 	Allocator* _allocator;

+ 9 - 0
src/core/strings/dynamic_string.h

@@ -220,4 +220,13 @@ inline const char* DynamicString::c_str() const
 	return array::begin(_data);
 }
 
+template <>
+struct hash<DynamicString>
+{
+	u32 operator()(const DynamicString& val) const
+	{
+		return val.to_string_id()._id;
+	}
+};
+
 } // namespace crown

+ 18 - 14
src/resource/data_compiler.cpp

@@ -5,7 +5,6 @@
 
 #include "config.h"
 #include "core/containers/hash_map.h"
-#include "core/containers/map.h"
 #include "core/containers/vector.h"
 #include "core/filesystem/file.h"
 #include "core/filesystem/filesystem_disk.h"
@@ -141,7 +140,7 @@ void DataCompiler::add_tree(const char* path)
 {
 	TempAllocator512 ta;
 	DynamicString source_dir(ta);
-	source_dir = map::get(_source_dirs, source_dir, source_dir);
+	source_dir = hash_map::get(_source_dirs, source_dir, source_dir);
 
 	_source_fs.set_prefix(source_dir.c_str());
 	DataCompiler::scan_source_dir(source_dir.c_str(), path);
@@ -236,7 +235,7 @@ void DataCompiler::map_source_dir(const char* name, const char* source_dir)
 	DynamicString sdir(ta);
 	sname.set(name, strlen32(name));
 	sdir.set(source_dir, strlen32(source_dir));
-	map::set(_source_dirs, sname, sdir);
+	hash_map::set(_source_dirs, sname, sdir);
 }
 
 void DataCompiler::source_dir(const char* resource_name, DynamicString& source_dir)
@@ -255,8 +254,8 @@ void DataCompiler::source_dir(const char* resource_name, DynamicString& source_d
 	DynamicString empty(ta);
 	empty = "";
 
-	deffault   = map::get(_source_dirs, empty, empty);
-	source_dir = map::get(_source_dirs, source_name, deffault);
+	deffault   = hash_map::get(_source_dirs, empty, empty);
+	source_dir = hash_map::get(_source_dirs, source_name, deffault);
 }
 
 void DataCompiler::add_ignore_glob(const char* glob)
@@ -272,11 +271,13 @@ void DataCompiler::scan()
 	const s64 time_start = time::now();
 
 	// Scan all source directories
-	auto cur = map::begin(_source_dirs);
-	auto end = map::end(_source_dirs);
-
+	auto cur = hash_map::begin(_source_dirs);
+	auto end = hash_map::end(_source_dirs);
 	for (; cur != end; ++cur)
 	{
+		if (hash_map::is_hole(_source_dirs, cur))
+			continue;
+
 		DynamicString prefix(default_allocator());
 		path::join(prefix, cur->pair.second.c_str(), cur->pair.first.c_str());
 		_source_fs.set_prefix(prefix.c_str());
@@ -313,7 +314,7 @@ void DataCompiler::scan()
 	}
 
 	logi(DATA_COMPILER, "Scanned data in %.2fs", time::seconds(time::now() - time_start));
-	_file_monitor.start(map::begin(_source_dirs)->pair.second.c_str(), true, filemonitor_callback, this);
+	_file_monitor.start(hash_map::begin(_source_dirs)->pair.second.c_str(), true, filemonitor_callback, this);
 }
 
 bool DataCompiler::compile(const char* data_dir, const char* platform)
@@ -410,8 +411,8 @@ bool DataCompiler::compile(const char* data_dir, const char* platform)
 
 		if (success)
 		{
-			if (!map::has(_data_index, dst_path))
-				map::set(_data_index, dst_path, src_path);
+			if (!hash_map::has(_data_index, dst_path))
+				hash_map::set(_data_index, dst_path, src_path);
 		}
 		else
 		{
@@ -427,10 +428,13 @@ bool DataCompiler::compile(const char* data_dir, const char* platform)
 		{
 			StringStream ss(default_allocator());
 
-			auto cur = map::begin(_data_index);
-			auto end = map::end(_data_index);
+			auto cur = hash_map::begin(_data_index);
+			auto end = hash_map::end(_data_index);
 			for (; cur != end; ++cur)
 			{
+				if (hash_map::is_hole(_data_index, cur))
+					continue;
+
 				ss << "\"" << cur->pair.first.c_str() << "\" = \"" << cur->pair.second.c_str() << "\"\n";
 			}
 
@@ -484,7 +488,7 @@ void DataCompiler::filemonitor_callback(FileMonitorEvent::Enum fme, bool is_dir,
 	DynamicString resource_name_renamed(ta);
 	DynamicString source_dir(ta);
 
-	source_dir            = map::get(_source_dirs, source_dir, source_dir);
+	source_dir            = hash_map::get(_source_dirs, source_dir, source_dir);
 	resource_name         = &path[source_dir.length()+1]; // FIXME: add path::relative()
 	resource_name_renamed = path_renamed ? &path_renamed[source_dir.length()+1] : "";
 

+ 2 - 2
src/resource/data_compiler.h

@@ -30,11 +30,11 @@ struct DataCompiler
 
 	ConsoleServer* _console_server;
 	FilesystemDisk _source_fs;
-	Map<DynamicString, DynamicString> _source_dirs;
+	HashMap<DynamicString, DynamicString> _source_dirs;
 	HashMap<StringId64, ResourceTypeData> _compilers;
 	Vector<DynamicString> _files;
 	Vector<DynamicString> _globs;
-	Map<DynamicString, DynamicString> _data_index;
+	HashMap<DynamicString, DynamicString> _data_index;
 	FileMonitor _file_monitor;
 	jmp_buf _jmpbuf;
 

+ 0 - 9
src/resource/shader_resource.cpp

@@ -35,15 +35,6 @@
 
 namespace crown
 {
-template <>
-struct hash<DynamicString>
-{
-	u32 operator()(const DynamicString& val) const
-	{
-		return val.to_string_id()._id;
-	}
-};
-
 namespace shader_resource_internal
 {
 	struct DepthFunction