Skip to content

Commit d8876ad

Browse files
committed
Update base for Update on "[5.1/ N] set_option/get_option API with {backend_name, backend options} only"
This PR only expose the set_option/get_option API via the pair {backend_name, backend_options}, without necessarily backend options map. The backend options map and it's corresponding API will be exposed to another PR Reference PR in #11758 which exposes the set_option/get_option with backendoptions map too Differential Revision: [D77190316](https://our.internmc.facebook.com/intern/diff/D77190316/) [ghstack-poisoned]
1 parent 0e9e057 commit d8876ad

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

runtime/backend/options.h

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,9 @@ class BackendOptions {
9292
* @param value The boolean value to set
9393
* @return Error::Ok on success, Error::InvalidArgument if storage is full
9494
*/
95-
Error set_option(const char key[kMaxOptionKeyLength], bool value) noexcept {
96-
ET_CHECK_MSG(
97-
strlen(key) <= kMaxOptionKeyLength,
98-
"Option key %s (%zu) is too long (max %zu)",
99-
key,
100-
strlen(key),
101-
kMaxOptionKeyLength);
95+
template <size_t N>
96+
Error set_option(const char (&key)[N], bool value) noexcept {
97+
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
10298
return set_option_impl(key, value);
10399
}
104100

@@ -111,13 +107,9 @@ class BackendOptions {
111107
* @param value The integer value to set
112108
* @return Error::Ok on success, Error::InvalidArgument if storage is full
113109
*/
114-
Error set_option(const char key[kMaxOptionKeyLength], int value) noexcept {
115-
ET_CHECK_MSG(
116-
strlen(key) <= kMaxOptionKeyLength,
117-
"Option key %s (%zu) is too long (max %zu)",
118-
key,
119-
strlen(key),
120-
kMaxOptionKeyLength);
110+
template <size_t N>
111+
Error set_option(const char (&key)[N], int value) noexcept {
112+
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
121113
return set_option_impl(key, value);
122114
}
123115

@@ -133,14 +125,9 @@ class BackendOptions {
133125
* @param value The string value to set (must have static storage duration)
134126
* @return Error::Ok on success, Error::InvalidArgument if storage is full
135127
*/
136-
Error set_option(const char key[kMaxOptionKeyLength], const char* value) noexcept {
137-
ET_CHECK_MSG(
138-
strlen(key) <= kMaxOptionKeyLength,
139-
"Option key %s (%zu) is too long (max %zu)",
140-
key,
141-
strlen(key),
142-
kMaxOptionKeyLength);
143-
128+
template <size_t N>
129+
Error set_option(const char (&key)[N], const char* value) noexcept {
130+
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
144131
// Create a fixed-size array and copy the string
145132
std::array<char, kMaxOptionValueLength> arr;
146133
strncpy(arr.data(), value, kMaxOptionValueLength - 1);
@@ -159,7 +146,7 @@ class BackendOptions {
159146
*/
160147
template <typename T, size_t KeyLen>
161148
Error get_option(const char (&key)[KeyLen], T& out) const {
162-
ET_CHECK_MSG(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
149+
static_assert(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
163150
for (size_t i = 0; i < size_; ++i) {
164151
if (std::strcmp(options_[i].key, key) == 0) {
165152
// Special handling for string (convert array to const char*)

0 commit comments

Comments
 (0)