You've already forked godot
							
							
				mirror of
				https://github.com/godotengine/godot.git
				synced 2025-11-03 11:50:27 +00:00 
			
		
		
		
	Merge pull request #110709 from DeeJayLSP/dict-reserve
Add `reserve()` to `Dictionary`, apply to constructors on GDScript VM
This commit is contained in:
		@@ -305,6 +305,12 @@ void Dictionary::_ref(const Dictionary &p_from) const {
 | 
			
		||||
	_p = p_from._p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Dictionary::reserve(int p_new_capacity) {
 | 
			
		||||
	ERR_FAIL_COND_MSG(_p->read_only, "Dictionary is in read-only state.");
 | 
			
		||||
	ERR_FAIL_COND_MSG(p_new_capacity < 0, "New capacity must be non-negative.");
 | 
			
		||||
	_p->variant_map.reserve(p_new_capacity);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Dictionary::clear() {
 | 
			
		||||
	ERR_FAIL_COND_MSG(_p->read_only, "Dictionary is in read-only state.");
 | 
			
		||||
	_p->variant_map.clear();
 | 
			
		||||
@@ -613,6 +619,7 @@ Dictionary Dictionary::recursive_duplicate(bool p_deep, ResourceDeepDuplicateMod
 | 
			
		||||
		return n;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	n.reserve(_p->variant_map.size());
 | 
			
		||||
	if (p_deep) {
 | 
			
		||||
		bool is_call_chain_end = recursion_count == 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -72,6 +72,7 @@ public:
 | 
			
		||||
 | 
			
		||||
	int size() const;
 | 
			
		||||
	bool is_empty() const;
 | 
			
		||||
	void reserve(int p_new_capacity);
 | 
			
		||||
	void clear();
 | 
			
		||||
	void sort();
 | 
			
		||||
	void merge(const Dictionary &p_dictionary, bool p_overwrite = false);
 | 
			
		||||
 
 | 
			
		||||
@@ -1829,7 +1829,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
 | 
			
		||||
 | 
			
		||||
				int argc = _code_ptr[ip + 1];
 | 
			
		||||
				Dictionary dict;
 | 
			
		||||
 | 
			
		||||
				dict.reserve(argc);
 | 
			
		||||
				for (int i = 0; i < argc; i++) {
 | 
			
		||||
					GET_INSTRUCTION_ARG(k, i * 2 + 0);
 | 
			
		||||
					GET_INSTRUCTION_ARG(v, i * 2 + 1);
 | 
			
		||||
@@ -1867,7 +1867,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
 | 
			
		||||
 | 
			
		||||
				Dictionary dict;
 | 
			
		||||
				dict.set_typed(key_builtin_type, key_native_type, *key_script_type, value_builtin_type, value_native_type, *value_script_type);
 | 
			
		||||
 | 
			
		||||
				dict.reserve(argc);
 | 
			
		||||
				for (int i = 0; i < argc; i++) {
 | 
			
		||||
					GET_INSTRUCTION_ARG(k, i * 2 + 0);
 | 
			
		||||
					GET_INSTRUCTION_ARG(v, i * 2 + 1);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user