@@ -162,32 +162,34 @@ SmallVector<int64_t> static getStridedSliceInsertionIndices(
162162 " rank of 'large' cannot be lower than the number of offsets" );
163163 unsigned delta = large.size () - small.size ();
164164 unsigned nOffsets = offsets.size ();
165- auto getSmall = [&](int64_t i) { return i >= delta ? small[i - delta] : 1 ; };
166- auto getOffset = [&](int64_t i) { return i < nOffsets ? offsets[i] : 0 ; };
165+ auto getSmall = [&](int64_t i) -> int64_t {
166+ return i >= delta ? small[i - delta] : 1 ;
167+ };
168+ auto getOffset = [&](int64_t i) -> int64_t {
169+ return i < nOffsets ? offsets[i] : 0 ;
170+ };
167171
168172 // Using 2 vectors of indices, at each iteration populate the updated set of
169173 // indices based on the old set of indices, and the size of the small vector
170174 // in the current iteration.
171175 SmallVector<int64_t > indices{0 };
172- SmallVector<int64_t > nextIndices;
173176 int64_t stride = 1 ;
174177 for (int i = large.size () - 1 ; i >= 0 ; --i) {
175- auto currentSize = indices.size ();
176- auto smallSize = getSmall (i);
177- auto nextSize = currentSize * smallSize;
178- nextIndices. resize (nextSize);
178+ int64_t currentSize = indices.size ();
179+ int64_t smallSize = getSmall (i);
180+ int64_t nextSize = currentSize * smallSize;
181+ SmallVector< int64_t > nextIndices (nextSize);
179182 int64_t *base = nextIndices.begin ();
180183 int64_t offset = getOffset (i) * stride;
181184 for (int j = 0 ; j < smallSize; ++j) {
182- for (uint64_t k = 0 ; k < currentSize; ++k) {
185+ for (int k = 0 ; k < currentSize; ++k) {
183186 base[k] = indices[k] + offset;
184187 }
185188 offset += stride;
186189 base += currentSize;
187190 }
188191 stride *= large[i];
189- std::swap (indices, nextIndices);
190- nextIndices.clear ();
192+ indices = std::move (nextIndices);
191193 }
192194 return indices;
193195}
0 commit comments