google / guava

Google core libraries for Java
Apache License 2.0
50.2k stars 10.91k forks source link

Ints.reverse(int[]), etc. #502

Closed gissuebot closed 10 years ago

gissuebot commented 10 years ago

Original issue created by ogregoire on 2010-12-17 at 01:35 PM


A method for reversing the values of an array of primitive would be welcome.

Use case is the same as with Collections.reverse or Iterables.reverse.

gissuebot commented 10 years ago

Original comment posted by finnw1 on 2010-12-17 at 03:41 PM


Why not use one of the variants of asList() from com.google.common.primitives?

e.g.

double[] array; //... Collections.reverse(Doubles.asList(array));

gissuebot commented 10 years ago

Original comment posted by ogregoire on 2010-12-17 at 04:36 PM


I suppose I could, but I hope it to be optimized for the use of an array. I especially don't like all the autoboxing stuff to happen as well as all the checks done inside the set method of the Primitives.asList() view.

Actually since I'm purposely using an array and not a list, I'd hope this could be an argument to see the reverse method implemented in the Primitives classes.

Meanwhile, I'll sure use your suggestion!

gissuebot commented 10 years ago

Original comment posted by kevinb@google.com on 2011-01-12 at 09:56 PM


I suspect this might only be used once in a blue moon, and it may be acceptable for such users to just bang out the 3-line helper method themselves. However, I'm keeping it open, at least for now.


Status: Accepted Labels: Type-Enhancement

gissuebot commented 10 years ago

Original comment posted by finnw1 on 2011-01-22 at 01:31 PM


I actually use this quite regularly, but so far it has never been a performance bottleneck so the autoboxing list has always been sufficient.

gissuebot commented 10 years ago

Original comment posted by kevinb@google.com on 2011-02-06 at 07:17 PM


Since {Lists,Collections}.reverse(Ints.asList()) are functional equivalents, covering both the view and the edit-in-place use cases, and since when one needs higher performance it's not hard to hand-code the "algorithm", this really rests on our discovering that this is a very common thing to want to do. So far from perusing internal code I see virtually no evidence that this is the case.


Status: WontFix