Skip to content

Remove IndexedInts.iterator()#4811

Merged
drcrallen merged 6 commits intoapache:masterfrom
metamx:indexed-ints-no-iterator
Sep 21, 2017
Merged

Remove IndexedInts.iterator()#4811
drcrallen merged 6 commits intoapache:masterfrom
metamx:indexed-ints-no-iterator

Conversation

@leventov
Copy link
Copy Markdown
Member

@leventov leventov commented Sep 15, 2017

To avoid accidental boxing for-each iteration like for (Integer i : indexedInts) {...}, that did actually happen several times in production code.

  • IndexableAdapter.getBitmapIndex() is renamed to getBitmapValues() and it's return type is changed to BitmapValues

@drcrallen
Copy link
Copy Markdown
Contributor

@leventov would an IntStream make sense in any of these cases?

@gianm
Copy link
Copy Markdown
Contributor

gianm commented Sep 16, 2017

CI failures are (partially?) from BitmapIndexedInts, where get(i) is unsupported since it would be too slow to use anyway compared to iterator(). I guess the foreach loops should be replaced to loops that use the IntIterator rather than loops that use get.

@leventov leventov changed the title Remove IndexedInts.iterator() Make IndexedInts to not extend Iterable Sep 16, 2017
@leventov leventov changed the title Make IndexedInts to not extend Iterable Remove IndexedInts.iterator() Sep 17, 2017
}
};

int size();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the most common use for size() is as an isEmpty() check, but the size() method in some bitmap implementations is not straight forward. Would it make sense to get rid of size() and have a isEmpty() instead, or have an isEmpty() in addition to size()?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait, i was looking at ImmutableBitmap::size, so it might be outside the scope of this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leventov
Copy link
Copy Markdown
Member Author

@gianm @drcrallen do you have more comments here?

@CalledFromHotLoop
int get(int index);

default void forEach(IntConsumer action)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? This is used only in tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I added this for nicer code in tests. I think it's ok

@drcrallen drcrallen merged commit a9d8539 into apache:master Sep 21, 2017
@drcrallen drcrallen deleted the indexed-ints-no-iterator branch September 21, 2017 04:25
@drcrallen drcrallen added this to the 0.11.1 milestone Sep 21, 2017
leventov added a commit to metamx/druid that referenced this pull request Oct 4, 2017
* Remove IndexedInts.iterator()

* Retain IndexedInts.iterator(), but don't extend Iterable

* Add BitmapValues

* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants