| 287 | } |
| 288 | |
| 289 | void UserDefault::setStringForKey(const char* pKey, std::string_view value) |
| 290 | { |
| 291 | // ignore empty key |
| 292 | if (!pKey || !*pKey) |
| 293 | { |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | setValueForKey(pKey, value); |
| 298 | |
| 299 | #if !USER_DEFAULT_PLAIN_MODE |
| 300 | if (_rwmmap) |
| 301 | { |
| 302 | yasio::obstream obs; |
| 303 | if (_encryptEnabled) |
| 304 | { |
| 305 | ud_write_v_s(this, obs, pKey); |
| 306 | ud_write_v_s(this, obs, value); |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | obs.write_v(pKey); |
| 311 | obs.write_v(value); |
| 312 | } |
| 313 | |
| 314 | if ((_realSize + obs.length() + sizeof(udflen_t)) < _curMapSize) |
| 315 | { // fast append entity without flush |
| 316 | // increase entities count |
| 317 | yasio::obstream::swrite(_rwmmap->data(), 1 + yasio::ibstream::sread<udflen_t>(_rwmmap->data())); |
| 318 | |
| 319 | // append entity |
| 320 | ::memcpy(_rwmmap->data() + sizeof(udflen_t) + _realSize, obs.data(), obs.length()); |
| 321 | _realSize += static_cast<int>(obs.length()); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | flush(); |
| 326 | } |
| 327 | } |
| 328 | #else |
| 329 | flush(); |
| 330 | #endif |
| 331 | } |
| 332 | |
| 333 | void UserDefault::setValueForKey(std::string_view key, std::string_view value) |
| 334 | { |