| 293 | return; |
| 294 | } |
| 295 | disabled_ = false; |
| 296 | std::fprintf(stderr, "[pc] enabled: cap=%d family=%s\n", cap_, markers_.family.c_str()); |
| 297 | } |
| 298 | |
| 299 | // ── LRU helpers ───────────────────────────────────────────────────────── |
| 300 | |
| 301 | int PrefixCache::find_entry(const PrefixHash & h) const { |
| 302 | for (int i = 0; i < (int)entries_.size(); i++) { |
| 303 | if (entries_[i].hash == h) return i; |
| 304 | } |
| 305 | return -1; |
| 306 | } |
| 307 | |
| 308 | void PrefixCache::move_to_end(int idx) { |
| 309 | if (idx < 0 || idx >= (int)entries_.size()) return; |
| 310 | auto e = std::move(entries_[idx]); |
| 311 | entries_.erase(entries_.begin() + idx); |
| 312 | entries_.push_back(std::move(e)); |
| 313 | } |
| 314 | |
| 315 | int PrefixCache::find_full_entry(const PrefixHash & h) const { |
| 316 | for (int i = 0; i < (int)full_entries_.size(); i++) { |
| 317 | if (full_entries_[i].hash == h) return i; |
| 318 | } |
| 319 | return -1; |
| 320 | } |
| 321 | |
| 322 | void PrefixCache::move_full_to_end(int idx) { |
| 323 | if (idx < 0 || idx >= (int)full_entries_.size()) return; |
| 324 | auto e = std::move(full_entries_[idx]); |
| 325 | full_entries_.erase(full_entries_.begin() + idx); |
| 326 | full_entries_.push_back(std::move(e)); |
| 327 | } |
| 328 | |
| 329 | // ── Inline prefix cache ───────────────────────────────────────────────── |
| 330 | |
| 331 | std::pair<int, int> PrefixCache::lookup(const std::vector<int32_t> & prompt_ids) { |
| 332 | if (disabled_) return {-1, 0}; |
| 333 |
no test coverage detected