Commit 0c69981
Skip memmove in prepareInputBuffer when trailing space suffices
Summary:
Re-lands D95740314 with a bug fix.
In `prepareInputBuffer()`, when `inputData_` already points into `inputBuffer_` and there is enough trailing capacity for the requested size, we can skip the memmove that compacts data to the front of the buffer. This avoids unnecessary data movement in the common case where chunks are consumed incrementally.
The original D95740314 had a bug: `ensureInput()` appended new data at `inputBuffer_->asMutable<char>() + inputSize_` (buffer start + inputSize_), which is wrong when `inputData_` is mid-buffer after the memmove skip. Fixed by changing the memcpy destination to `const_cast<char*>(inputData_) + inputSize_`, which correctly appends relative to wherever `inputData_` currently points.
All usage sites of `inputData_`/`inputBuffer_` were audited:
- `loadNextChunk()`: reads from `inputData_`, no writes to buffer — safe
- `ensureInputIncremental_hack()`: arithmetic relative to `inputData_` — safe
- `prepareInputBuffer()` realloc path: copies from `inputData_`, updates pointer — safe
- `prepareInputBuffer()` memmove path: resets `inputData_` to buffer start — safe
- `seekToChunk()`: clean reset of `inputData_` and `inputSize_` — safe
Differential Revision: D973297251 parent b021c53 commit 0c69981
File tree
2 files changed
+61
-4
lines changed- dwio/nimble/velox/selective
- tests
2 files changed
+61
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
110 | 121 | | |
111 | 122 | | |
112 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
151 | 197 | | |
152 | 198 | | |
153 | 199 | | |
| |||
0 commit comments