mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
crc32 on strings is performed in one pass - removed the strlen() call.
This commit is contained in:
parent
691ca46978
commit
2d111ccb55
26
imgui.cpp
26
imgui.cpp
@ -1,4 +1,4 @@
|
|||||||
// ImGui library v1.19
|
// ImGui library v1.19 wip
|
||||||
// See ImGui::ShowTestWindow() for sample code.
|
// See ImGui::ShowTestWindow() for sample code.
|
||||||
// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
|
// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
|
||||||
// Get latest version at https://github.com/ocornut/imgui
|
// Get latest version at https://github.com/ocornut/imgui
|
||||||
@ -540,6 +540,7 @@ static const char* ImStristr(const char* haystack, const char* needle, const cha
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pass data_size==0 for zero-terminated string
|
||||||
static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
|
static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
|
||||||
{
|
{
|
||||||
static ImU32 crc32_lut[256] = { 0 };
|
static ImU32 crc32_lut[256] = { 0 };
|
||||||
@ -556,8 +557,19 @@ static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
|
|||||||
}
|
}
|
||||||
ImU32 crc = ~seed;
|
ImU32 crc = ~seed;
|
||||||
const unsigned char* current = (const unsigned char*)data;
|
const unsigned char* current = (const unsigned char*)data;
|
||||||
|
|
||||||
|
if (data_size > 0)
|
||||||
|
{
|
||||||
|
// Known size
|
||||||
while (data_size--)
|
while (data_size--)
|
||||||
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
|
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Zero-terminated string
|
||||||
|
while (unsigned char c = *current++)
|
||||||
|
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
|
||||||
|
}
|
||||||
return ~crc;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1243,7 +1255,7 @@ ImGuiWindow::~ImGuiWindow()
|
|||||||
ImGuiID ImGuiWindow::GetID(const char* str)
|
ImGuiID ImGuiWindow::GetID(const char* str)
|
||||||
{
|
{
|
||||||
const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
|
const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
|
||||||
const ImGuiID id = ImCrc32(str, strlen(str), seed); // FIXME-OPT: crc32 function/variant should handle zero-terminated strings
|
const ImGuiID id = ImCrc32(str, 0, seed);
|
||||||
RegisterAliveId(id);
|
RegisterAliveId(id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -7071,13 +7083,9 @@ void ImGui::ShowTestWindow(bool* opened)
|
|||||||
ImGui::InputInt("input int", &i0);
|
ImGui::InputInt("input int", &i0);
|
||||||
ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
|
ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
|
||||||
|
|
||||||
//static float vec2a[3] = { 0.10f, 0.20f };
|
static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
|
||||||
//ImGui::InputFloat2("input float2", vec2a);
|
//ImGui::InputFloat2("input float2", vec4a);
|
||||||
|
ImGui::InputFloat3("input float3", vec4a);
|
||||||
static float vec3a[3] = { 0.10f, 0.20f, 0.30f };
|
|
||||||
ImGui::InputFloat3("input float3", vec3a);
|
|
||||||
|
|
||||||
//static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
|
|
||||||
//ImGui::InputFloat4("input float4", vec4a);
|
//ImGui::InputFloat4("input float4", vec4a);
|
||||||
|
|
||||||
static int i1=0;
|
static int i1=0;
|
||||||
|
2
imgui.h
2
imgui.h
@ -1,4 +1,4 @@
|
|||||||
// ImGui library v1.19
|
// ImGui library v1.19 wip
|
||||||
// See .cpp file for commentary.
|
// See .cpp file for commentary.
|
||||||
// See ImGui::ShowTestWindow() for sample code.
|
// See ImGui::ShowTestWindow() for sample code.
|
||||||
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
||||||
|
Loading…
Reference in New Issue
Block a user