Skip to content

Commit 0710cbd

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in faiss/impl/ResultHandler.h
Summary: Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so. This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug. **What's a shadowed variable?** Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs. This diff fixes such an issue by renaming the variable. - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: algoriddle Differential Revision: D52582910 fbshipit-source-id: 92ee06e819f15c411a3fee75a6c9e17fba96a7f3
1 parent 42b6216 commit 0710cbd

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

faiss/impl/ResultHandler.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ struct HeapResultHandler {
8282
size_t i0, i1;
8383

8484
/// begin
85-
void begin_multiple(size_t i0, size_t i1) {
86-
this->i0 = i0;
87-
this->i1 = i1;
88-
for (size_t i = i0; i < i1; i++) {
85+
void begin_multiple(size_t i0_2, size_t i1_2) {
86+
this->i0 = i0_2;
87+
this->i1 = i1_2;
88+
for (size_t i = i0_2; i < i1_2; i++) {
8989
heap_heapify<C>(k, heap_dis_tab + i * k, heap_ids_tab + i * k);
9090
}
9191
}
@@ -231,13 +231,13 @@ struct ReservoirResultHandler {
231231
size_t i;
232232

233233
/// begin results for query # i
234-
void begin(size_t i) {
234+
void begin(size_t i_2) {
235235
res1 = ReservoirTopN<C>(
236236
hr.k,
237237
hr.capacity,
238238
reservoir_dis.data(),
239239
reservoir_ids.data());
240-
this->i = i;
240+
this->i = i_2;
241241
}
242242

243243
/// add one result for query i
@@ -264,18 +264,18 @@ struct ReservoirResultHandler {
264264
std::vector<ReservoirTopN<C>> reservoirs;
265265

266266
/// begin
267-
void begin_multiple(size_t i0, size_t i1) {
268-
this->i0 = i0;
269-
this->i1 = i1;
270-
reservoir_dis.resize((i1 - i0) * capacity);
271-
reservoir_ids.resize((i1 - i0) * capacity);
267+
void begin_multiple(size_t i0_2, size_t i1_2) {
268+
this->i0 = i0_2;
269+
this->i1 = i1_2;
270+
reservoir_dis.resize((i1_2 - i0_2) * capacity);
271+
reservoir_ids.resize((i1_2 - i0_2) * capacity);
272272
reservoirs.clear();
273-
for (size_t i = i0; i < i1; i++) {
273+
for (size_t i = i0_2; i < i1_2; i++) {
274274
reservoirs.emplace_back(
275275
k,
276276
capacity,
277-
reservoir_dis.data() + (i - i0) * capacity,
278-
reservoir_ids.data() + (i - i0) * capacity);
277+
reservoir_dis.data() + (i - i0_2) * capacity,
278+
reservoir_ids.data() + (i - i0_2) * capacity);
279279
}
280280
}
281281

@@ -363,9 +363,9 @@ struct RangeSearchResultHandler {
363363
int pr = 0;
364364

365365
/// begin
366-
void begin_multiple(size_t i0, size_t i1) {
367-
this->i0 = i0;
368-
this->i1 = i1;
366+
void begin_multiple(size_t i0_2, size_t i1_2) {
367+
this->i0 = i0_2;
368+
this->i1 = i1_2;
369369
}
370370

371371
/// add results for query i0..i1 and j0..j1
@@ -443,8 +443,8 @@ struct SingleBestResultHandler {
443443
SingleResultHandler(SingleBestResultHandler& hr) : hr(hr) {}
444444

445445
/// begin results for query # i
446-
void begin(const size_t current_idx) {
447-
this->current_idx = current_idx;
446+
void begin(const size_t current_idx_2) {
447+
this->current_idx = current_idx_2;
448448
min_dis = HUGE_VALF;
449449
min_idx = -1;
450450
}
@@ -467,19 +467,19 @@ struct SingleBestResultHandler {
467467
size_t i0, i1;
468468

469469
/// begin
470-
void begin_multiple(size_t i0, size_t i1) {
471-
this->i0 = i0;
472-
this->i1 = i1;
470+
void begin_multiple(size_t i0_2, size_t i1_2) {
471+
this->i0 = i0_2;
472+
this->i1 = i1_2;
473473

474-
for (size_t i = i0; i < i1; i++) {
474+
for (size_t i = i0_2; i < i1_2; i++) {
475475
this->dis_tab[i] = HUGE_VALF;
476476
}
477477
}
478478

479479
/// add results for query i0..i1 and j0..j1
480-
void add_results(size_t j0, size_t j1, const T* dis_tab) {
480+
void add_results(size_t j0, size_t j1, const T* dis_tab_2) {
481481
for (int64_t i = i0; i < i1; i++) {
482-
const T* dis_tab_i = dis_tab + (j1 - j0) * (i - i0) - j0;
482+
const T* dis_tab_i = dis_tab_2 + (j1 - j0) * (i - i0) - j0;
483483

484484
auto& min_distance = this->dis_tab[i];
485485
auto& min_index = this->ids_tab[i];

0 commit comments

Comments
 (0)