mengdiwang / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by ogregoire on 17 Dec 2010 at 1:35

GoogleCodeExporter commented 9 years ago
Why not use one of the variants of asList() from com.google.common.primitives?

e.g.

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

Original comment by fin...@gmail.com on 17 Dec 2010 at 3:41

GoogleCodeExporter commented 9 years ago
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!

Original comment by ogregoire on 17 Dec 2010 at 4:36

GoogleCodeExporter commented 9 years ago
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.

Original comment by kevinb@google.com on 12 Jan 2011 at 9:56

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

Original comment by fin...@gmail.com on 22 Jan 2011 at 1:31

GoogleCodeExporter commented 9 years ago
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.

Original comment by kevinb@google.com on 6 Feb 2011 at 7:17

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09