Jelajahi Sumber

resource: do not pre-allocate

Daniele Bartolini 6 tahun lalu
induk
melakukan
7c8306e4d0
1 mengubah file dengan 3 tambahan dan 4 penghapusan
  1. 3 4
      src/resource/unit_compiler.cpp

+ 3 - 4
src/resource/unit_compiler.cpp

@@ -317,8 +317,6 @@ u32 component_index(const JsonArray& components, const StringView& id)
 s32 UnitCompiler::compile_unit_from_json(const char* json)
 {
 	Buffer data(default_allocator());
-	array::reserve(data, 1024*1024);
-
 	u32 num_prefabs = 1;
 
 	TempAllocator4096 ta;
@@ -342,9 +340,10 @@ s32 UnitCompiler::compile_unit_from_json(const char* json)
 		path += ".unit";
 
 		Buffer buf = read_unit(path.c_str());
-		const char* data_end = array::end(data);
+		u32 offset = array::size(data);
 		array::push(data, array::begin(buf), array::size(buf));
-		sjson::parse(prefabs[i + 1], data_end);
+		array::push_back(data, '\0');
+		sjson::parse(prefabs[i + 1], array::begin(data) + offset);
 	}
 
 	JsonObject& prefab_root = prefabs[num_prefabs - 1];