| 140 | } |
| 141 | |
| 142 | void FrameInfoCache::update_cache( |
| 143 | int key, |
| 144 | const SmallVector<std::pair<PyFrameObject*, FrameInfoPtr>, 100>& frames) { |
| 145 | stack_cache.resize(key + frames.size() + 1); |
| 146 | auto it = frames.rbegin(); |
| 147 | auto cur_key = key + 1; |
| 148 | for (; it != frames.rend(); it++, cur_key++) { |
| 149 | auto&& [frame, finfo] = *it; |
| 150 | stack_cache[cur_key] = finfo; |
| 151 | if (auto* key_ptr = TraceKeyWrapper::try_cast(frame->f_trace)) { |
| 152 | key_ptr->key = cur_key; |
| 153 | } else { |
| 154 | auto* py_key = TraceKeyWrapper::make(cur_key, frame->f_trace); |
| 155 | frame->f_trace = py_key; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | int FrameInfoCache::get_frame_key(PyFrameObject* frame) { |
| 161 | auto* key = TraceKeyWrapper::try_cast(frame->f_trace); |