mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +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:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "frc/smartdashboard/MechanismLigament2d.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <wpi/StringExtras.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -36,8 +36,10 @@ void MechanismLigament2d::UpdateEntries(
|
||||
|
||||
void MechanismLigament2d::SetColor(const Color8Bit& color) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
std::snprintf(m_color, sizeof(m_color), "#%02X%02X%02X", color.red,
|
||||
color.green, color.blue);
|
||||
|
||||
wpi::format_to_n_c_str(m_color, sizeof(m_color), "#{:02X}{:02X}{:02X}",
|
||||
color.red, color.green, color.blue);
|
||||
|
||||
if (m_colorEntry) {
|
||||
m_colorEntry.Set(m_color);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user