فهرست منبع

core: add HASH_MAP_SKIP_HOLE() and JSON_OBJECT_SKIP_HOLE()

Daniele Bartolini 6 سال پیش
والد
کامیت
c1ae79d6c6

+ 4 - 0
src/core/containers/hash_map.h

@@ -397,4 +397,8 @@ HashMap<TKey, TValue, Hash, KeyEqual>& HashMap<TKey, TValue, Hash, KeyEqual>::op
 	return *this;
 }
 
+#define HASH_MAP_SKIP_HOLE(m, cur) \
+	if (hash_map::is_hole(m, cur)) \
+		continue
+
 } // namespace crown

+ 2 - 0
src/core/json/json_object.h

@@ -73,3 +73,5 @@ inline const char* JsonObject::operator[](const FixedString& key) const
 }
 
 }
+
+#define JSON_OBJECT_SKIP_HOLE(jo, cur) HASH_MAP_SKIP_HOLE(jo._map, cur)

+ 14 - 28
src/resource/data_compiler.cpp

@@ -133,8 +133,7 @@ void SourceIndex::scan(const HashMap<DynamicString, DynamicString>& source_dirs)
 	auto end = hash_map::end(source_dirs);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(source_dirs, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(source_dirs, cur);
 
 		DynamicString prefix(default_allocator());
 		path::join(prefix, cur->second.c_str(), cur->first.c_str());
@@ -246,8 +245,7 @@ static void read_data_versions(HashMap<DynamicString, u32>& versions, Filesystem
 	auto end = json_object::end(object);
 	for (; cur != end; ++cur)
 	{
-		if (json_object::is_hole(object, cur))
-			continue;
+		JSON_OBJECT_SKIP_HOLE(object, cur);
 
 		TempAllocator256 ta;
 		DynamicString type(ta);
@@ -269,8 +267,7 @@ static void read_data_index(HashMap<StringId64, DynamicString>& index, Filesyste
 	auto end = json_object::end(object);
 	for (; cur != end; ++cur)
 	{
-		if (json_object::is_hole(object, cur))
-			continue;
+		JSON_OBJECT_SKIP_HOLE(object, cur);
 
 		TempAllocator256 ta;
 		StringId64 dst_name;
@@ -295,8 +292,7 @@ static void read_data_mtimes(HashMap<StringId64, u64>& mtimes, FilesystemDisk& d
 	auto end = json_object::end(object);
 	for (; cur != end; ++cur)
 	{
-		if (json_object::is_hole(object, cur))
-			continue;
+		JSON_OBJECT_SKIP_HOLE(object, cur);
 
 		TempAllocator64 ta;
 		StringId64 dst_name;
@@ -323,8 +319,7 @@ static void read_data_dependencies(DataCompiler& dc, FilesystemDisk& data_fs, co
 	auto end = json_object::end(object);
 	for (; cur != end; ++cur)
 	{
-		if (json_object::is_hole(object, cur))
-			continue;
+		JSON_OBJECT_SKIP_HOLE(object, cur);
 
 		StringId64 dst_name;
 		dst_name.parse(cur->first.data());
@@ -351,8 +346,7 @@ static void write_data_index(FilesystemDisk& data_fs, const char* filename, cons
 		auto end = hash_map::end(index);
 		for (; cur != end; ++cur)
 		{
-			if (hash_map::is_hole(index, cur))
-				continue;
+			HASH_MAP_SKIP_HOLE(index, cur);
 
 			TempAllocator256 ta;
 			DynamicString str(ta);
@@ -377,8 +371,7 @@ static void write_data_versions(FilesystemDisk& data_fs, const char* filename, c
 		auto end = hash_map::end(versions);
 		for (; cur != end; ++cur)
 		{
-			if (hash_map::is_hole(versions, cur))
-				continue;
+			HASH_MAP_SKIP_HOLE(versions, cur);
 
 			ss << cur->first.c_str() << " = " << cur->second << "\n";
 		}
@@ -401,8 +394,7 @@ static void write_data_mtimes(FilesystemDisk& data_fs, const char* filename, con
 		auto end = hash_map::end(mtimes);
 		for (; cur != end; ++cur)
 		{
-			if (hash_map::is_hole(mtimes, cur))
-				continue;
+			HASH_MAP_SKIP_HOLE(mtimes, cur);
 
 			TempAllocator64 ta;
 			DynamicString key(ta);
@@ -421,8 +413,7 @@ static void write_source_files(StringStream& ss, HashMap<DynamicString, u32> sou
 	auto end = hash_map::end(sources);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(sources, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(sources, cur);
 
 		ss << "    \"" << cur->first.c_str() << "\"\n";
 	}
@@ -439,8 +430,7 @@ static void write_data_dependencies(FilesystemDisk& data_fs, const char* filenam
 		auto end = hash_map::end(dependencies);
 		for (; cur != end; ++cur)
 		{
-			if (hash_map::is_hole(dependencies, cur))
-				continue;
+			HASH_MAP_SKIP_HOLE(dependencies, cur);
 
 			TempAllocator64 ta;
 			DynamicString key(ta);
@@ -578,8 +568,7 @@ void DataCompiler::scan_and_restore(const char* data_dir)
 	auto end = hash_map::end(_source_dirs);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(_source_dirs, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(_source_dirs, cur);
 
 		DynamicString prefix(default_allocator());
 		path::join(prefix, cur->second.c_str(), cur->first.c_str());
@@ -688,8 +677,7 @@ bool DataCompiler::dependency_changed(const DynamicString& src_path, ResourceId
 	auto end = hash_map::end(deps);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(deps, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(deps, cur);
 
 		if (src_path == cur->first)
 			continue;
@@ -714,8 +702,7 @@ bool DataCompiler::version_changed(const DynamicString& src_path, ResourceId id)
 	auto end = hash_map::end(deps);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(deps, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(deps, cur);
 
 		if (src_path == cur->first)
 			continue;
@@ -759,8 +746,7 @@ bool DataCompiler::compile(const char* data_dir, const char* platform)
 	auto end = hash_map::end(_source_index._paths);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(_source_index._paths, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(_source_index._paths, cur);
 
 		const DynamicString& src_path = cur->first;
 		const char* filename = src_path.c_str();

+ 2 - 4
src/resource/material_resource.cpp

@@ -81,8 +81,7 @@ namespace material_resource_internal
 		auto end = json_object::end(object);
 		for (; cur != end; ++cur)
 		{
-			if (json_object::is_hole(object, cur))
-				continue;
+			JSON_OBJECT_SKIP_HOLE(object, cur);
 
 			const FixedString key = cur->first;
 			const char* value     = cur->second;
@@ -122,8 +121,7 @@ namespace material_resource_internal
 		auto end = json_object::end(object);
 		for (; cur != end; ++cur)
 		{
-			if (json_object::is_hole(object, cur))
-				continue;
+			JSON_OBJECT_SKIP_HOLE(object, cur);
 
 			const FixedString key = cur->first;
 			const char* value     = cur->second;

+ 1 - 2
src/resource/mesh_resource.cpp

@@ -275,8 +275,7 @@ namespace mesh_resource_internal
 		auto end = json_object::end(geometries);
 		for (; cur != end; ++cur)
 		{
-			if (json_object::is_hole(geometries, cur))
-				continue;
+			JSON_OBJECT_SKIP_HOLE(geometries, cur);
 
 			const FixedString key = cur->first;
 			const char* geometry = cur->second;

+ 4 - 8
src/resource/physics_resource.cpp

@@ -301,8 +301,7 @@ namespace physics_config_resource_internal
 		auto end = json_object::end(object);
 		for (; cur != end; ++cur)
 		{
-			if (json_object::is_hole(object, cur))
-				continue;
+			JSON_OBJECT_SKIP_HOLE(object, cur);
 
 			const FixedString key = cur->first;
 			const char* value     = cur->second;
@@ -330,8 +329,7 @@ namespace physics_config_resource_internal
 		auto end = json_object::end(object);
 		for (; cur != end; ++cur)
 		{
-			if (json_object::is_hole(object, cur))
-				continue;
+			JSON_OBJECT_SKIP_HOLE(object, cur);
 
 			const FixedString key = cur->first;
 			const char* value     = cur->second;
@@ -384,8 +382,7 @@ namespace physics_config_resource_internal
 			auto end = json_object::end(object);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(object, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(object, cur);
 
 				const FixedString key = cur->first;
 				const StringId32 id   = StringId32(key.data(), key.length());
@@ -397,8 +394,7 @@ namespace physics_config_resource_internal
 			end = json_object::end(object);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(object, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(object, cur);
 
 				const FixedString key = cur->first;
 				const char* value     = cur->second;

+ 1 - 2
src/resource/resource_manager.cpp

@@ -38,8 +38,7 @@ ResourceManager::~ResourceManager()
 	auto end = hash_map::end(_rm);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(_rm, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(_rm, cur);
 
 		const StringId64 type = cur->first.type;
 		const StringId64 name = cur->first.name;

+ 6 - 12
src/resource/shader_resource.cpp

@@ -720,8 +720,7 @@ namespace shader_resource_internal
 			auto end = json_object::end(render_states);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(render_states, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(render_states, cur);
 
 				JsonObject obj(ta);
 				sjson::parse_object(cur->second, obj);
@@ -844,8 +843,7 @@ namespace shader_resource_internal
 			auto end = json_object::end(sampler_states);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(sampler_states, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(sampler_states, cur);
 
 				JsonObject obj(ta);
 				sjson::parse_object(cur->second, obj);
@@ -944,8 +942,7 @@ namespace shader_resource_internal
 			auto end = json_object::end(bgfx_shaders);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(bgfx_shaders, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(bgfx_shaders, cur);
 
 				JsonObject shader(ta);
 				sjson::parse_object(cur->second, shader);
@@ -992,8 +989,7 @@ namespace shader_resource_internal
 			auto end = json_object::end(bgfx_samplers);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(bgfx_samplers, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(bgfx_samplers, cur);
 
 				JsonObject sampler(ta);
 				sjson::parse_object(cur->second, sampler);
@@ -1031,8 +1027,7 @@ namespace shader_resource_internal
 			auto end = json_object::end(shaders);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(shaders, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(shaders, cur);
 
 				JsonObject obj(ta);
 				sjson::parse_object(cur->second, obj);
@@ -1162,8 +1157,7 @@ namespace shader_resource_internal
 			auto end = hash_map::end(shader._samplers);
 			for (; cur != end; ++cur)
 			{
-				if (hash_map::is_hole(shader._samplers, cur))
-					continue;
+				HASH_MAP_SKIP_HOLE(shader._samplers, cur);
 
 				const DynamicString& name = cur->first;
 				const DynamicString& sampler_state = cur->second;

+ 2 - 4
src/resource/state_machine_resource.cpp

@@ -305,8 +305,7 @@ namespace state_machine_internal
 				auto end = hash_map::end(_states);
 				for (; cur != end; ++cur)
 				{
-					if (hash_map::is_hole(_states, cur))
-						continue;
+					HASH_MAP_SKIP_HOLE(_states, cur);
 
 					const Guid& guid    = cur->first;
 					const StateInfo& si = cur->second;
@@ -374,8 +373,7 @@ namespace state_machine_internal
 			auto end = hash_map::end(_states);
 			for (; cur != end; ++cur)
 			{
-				if (hash_map::is_hole(_states, cur))
-					continue;
+				HASH_MAP_SKIP_HOLE(_states, cur);
 
 				const StateInfo& si = cur->second;
 				const u32 num_animations  = vector::size(si.animations);

+ 2 - 4
src/resource/unit_compiler.cpp

@@ -359,8 +359,7 @@ s32 UnitCompiler::compile_unit_from_json(const char* json)
 			auto end = json_object::end(modified_components);
 			for (; cur != end; ++cur)
 			{
-				if (json_object::is_hole(modified_components, cur))
-					continue;
+				JSON_OBJECT_SKIP_HOLE(modified_components, cur);
 
 				const FixedString key = cur->first;
 				const FixedString id(&key.data()[1], key.length()-1);
@@ -424,8 +423,7 @@ Buffer UnitCompiler::blob()
 	auto end = hash_map::end(_component_data);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(_component_data, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(_component_data, cur);
 
 		const u32 num = cur->second._num;
 

+ 1 - 2
src/world/material_manager.cpp

@@ -26,8 +26,7 @@ MaterialManager::~MaterialManager()
 	auto end = hash_map::end(_materials);
 	for (; cur != end; ++cur)
 	{
-		if (hash_map::is_hole(_materials, cur))
-			continue;
+		HASH_MAP_SKIP_HOLE(_materials, cur);
 
 		_allocator->deallocate(cur->second);
 	}