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,8 +4,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
@@ -539,11 +538,12 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchInfo
|
||||
JStringRef gameSpecificMessageRef{env, gameSpecificMessage};
|
||||
|
||||
HAL_MatchInfo halMatchInfo;
|
||||
std::snprintf(halMatchInfo.eventName, sizeof(halMatchInfo.eventName), "%s",
|
||||
eventNameRef.c_str());
|
||||
std::snprintf(reinterpret_cast<char*>(halMatchInfo.gameSpecificMessage),
|
||||
sizeof(halMatchInfo.gameSpecificMessage), "%s",
|
||||
gameSpecificMessageRef.c_str());
|
||||
wpi::format_to_n_c_str(halMatchInfo.eventName, sizeof(halMatchInfo.eventName),
|
||||
"{}", eventNameRef.str());
|
||||
wpi::format_to_n_c_str(
|
||||
reinterpret_cast<char*>(halMatchInfo.gameSpecificMessage),
|
||||
sizeof(halMatchInfo.gameSpecificMessage), "{}",
|
||||
gameSpecificMessageRef.str());
|
||||
halMatchInfo.gameSpecificMessageSize = gameSpecificMessageRef.size();
|
||||
halMatchInfo.matchType = (HAL_MatchType)matchType;
|
||||
halMatchInfo.matchNumber = matchNumber;
|
||||
|
||||
Reference in New Issue
Block a user