mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	ImVector: Made reserve() another silly one-liner. It's not longer than other functions and our weird obsessions deserve to be carried with stringent consistence. + Comments
This commit is contained in:
		
							
								
								
									
										14
									
								
								imgui.h
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								imgui.h
									
									
									
									
									
								
							| @@ -1200,19 +1200,7 @@ struct ImVector | ||||
|     inline int          _grow_capacity(int sz) const        { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > sz ? new_capacity : sz; } | ||||
|     inline void         resize(int new_size)                { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; } | ||||
|     inline void         resize(int new_size, const T& v)    { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; } | ||||
|     inline void         reserve(int new_capacity) | ||||
|     { | ||||
|         if (new_capacity <= Capacity) | ||||
|             return; | ||||
|         T* new_data = (T*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); | ||||
|         if (Data) | ||||
|         { | ||||
|             memcpy(new_data, Data, (size_t)Size * sizeof(T)); | ||||
|             ImGui::MemFree(Data); | ||||
|         } | ||||
|         Data = new_data; | ||||
|         Capacity = new_capacity; | ||||
|     } | ||||
|     inline void         reserve(int new_capacity)           { if (new_capacity <= Capacity) return; T* new_data = (T*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); ImGui::MemFree(Data); } Data = new_data; Capacity = new_capacity; } | ||||
|  | ||||
|     // NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. | ||||
|     inline void         push_back(const T& v)               { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user