* @brief Hot-path write keyed by Lua's interned string pointers; an identical value is a * successful no-op that leaves the slot version untouched. */
| 212 | * successful no-op that leaves the slot version untouched. |
| 213 | */ |
| 214 | bool DataModel::DataTableStore::setByInternedKey(const char* table, |
| 215 | const char* reg, |
| 216 | const RegisterValue& val) |
| 217 | { |
| 218 | Q_ASSERT(m_initialized); |
| 219 | Q_ASSERT(m_isComputed.size() == m_storage.size()); |
| 220 | |
| 221 | int idx = -1; |
| 222 | for (const auto& entry : m_internedKeyCache) { |
| 223 | if (entry.tablePtr == table && entry.regPtr == reg) { |
| 224 | idx = entry.storeIndex; |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if (idx == -1) { |
| 230 | const QString tableStr = QString::fromUtf8(table); |
| 231 | const QString regStr = QString::fromUtf8(reg); |
| 232 | idx = indexOf(tableStr, regStr); |
| 233 | m_internedKeyCache[m_internedKeyCacheNext] = {table, reg, idx}; |
| 234 | m_internedKeyCacheNext = (m_internedKeyCacheNext + 1) % kInternedKeyCacheSize; |
| 235 | } |
| 236 | |
| 237 | if (idx < 0) [[unlikely]] |
| 238 | return false; |
| 239 | |
| 240 | if (!m_isComputed[static_cast<size_t>(idx)]) [[unlikely]] { |
| 241 | qWarning() << "[DataTableStore] Cannot write to non-computed register" |
| 242 | << QLatin1StringView(table) << "/" << QLatin1StringView(reg); |
| 243 | return false; |
| 244 | } |
| 245 | |
| 246 | if (sameRegisterValue(m_storage[static_cast<size_t>(idx)], val)) |
| 247 | return true; |
| 248 | |
| 249 | m_storage[static_cast<size_t>(idx)] = val; |
| 250 | m_version[static_cast<size_t>(idx)] = ++m_writeClock; |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * @brief Returns true once initialize() has built the register storage. |
no test coverage detected