mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Replace std::snprintf() with wpi::format_to_n_c_str() (#5645)
fmtlib uses consteval format string processing, which makes it more efficient than std::snprintf(). snprintf()s in libuv, mpack, processstarter, and wpigui were left alone. processstarter uses stdlib only, and wpigui only depends on imgui. fmt::format_to_n() is analogous to std::format_to_n() (https://en.cppreference.com/w/cpp/utility/format/format_to_n) wpi::format_to_n_c_str() is a wrapper which adds the trailing NUL.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <fmt/format.h>
|
||||
#include <imgui.h>
|
||||
#include <ntcore_cpp.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpigui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
@@ -317,11 +318,13 @@ int main(int argc, char** argv) {
|
||||
char nameBuf[32];
|
||||
const char* name = glfwGetKeyName(*gEnterKey, 0);
|
||||
if (!name) {
|
||||
std::snprintf(nameBuf, sizeof(nameBuf), "%d", *gEnterKey);
|
||||
wpi::format_to_n_c_str(nameBuf, sizeof(nameBuf), "{}", *gEnterKey);
|
||||
|
||||
name = nameBuf;
|
||||
}
|
||||
std::snprintf(editLabel, sizeof(editLabel), "%s###edit",
|
||||
gKeyEdit ? "(press key)" : name);
|
||||
wpi::format_to_n_c_str(editLabel, sizeof(editLabel), "{}###edit",
|
||||
gKeyEdit ? "(press key)" : name);
|
||||
|
||||
if (ImGui::SmallButton(editLabel)) {
|
||||
gKeyEdit = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user