DaveAKing / guava-libraries

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

Range.OfXX, where XX is a primitive type? #1714

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

For one of my projects here:

https://github.com/fge/largetext

I use `Range` a lot; in fact, every time I invoke `.charAt()` on either a 
`LargeText` or any `TextRangeSubSequence` implementation, I use 
`range.contains()`.

Which means autoboxing takes place each time. And when I profile a run of a 
sample main, `.charAt()` being called a _lot_ by `Matcher`, a lot of autoboxing 
takes place.

Can it be possible to introduce `Range.OfInt` etc? Of course, I am aware that 
it would also require to introduce `RangeMap.OfInt` and the like....

Original issue reported on code.google.com by fgalie...@gmail.com on 5 Apr 2014 at 4:32

GoogleCodeExporter commented 9 years ago
Within Google, > 50% of all Ranges are either Integer or Long.

There may be some sense in providing special support for long-valued ranges 
(and probably not bothering with int anymore these days). *Ideally*, 
Range.open() and friends would just have long-valued overloads and you would 
get a LongRange that extends Range<Long>. (Problem: anyone currently passing 
(long, Long) would suffer a compilation breakage.)

And that class would have primitive versions of most methods, a primitive-based 
implementation, and an asSet() method that gives you a ContiguousSet without 
needing to pass in DiscreteDomain.longs().

All in all, this could get pretty hairy and I'm not sure it's the right place 
to spend time right now; I'm just updating this to sketch out what it might 
look like _if_ we did it.

Original comment by kevinb@google.com on 14 Apr 2014 at 10:38

GoogleCodeExporter commented 9 years ago
Uhwell, if you have `LongRange`, how far away is `IntRange`.

FWIW, I took the plunge in my project and developed a custom, limited purpose 
`IntRange`. I still use a `RangeMap`, so I have a `.asGuavaRange()` method as 
well.

But this simple change made speed go up by 60% and memory usage go down by 70%! 
Yes, most memory was consumed by `Pattern` calling `.charAt()`, which in my 
implementation starts to check whether the current character range 
`.contains()` the queried character index... It has managed to dwarf `char[]` 
memory usage, which is quite contradictory!

Original comment by fgalie...@gmail.com on 14 Apr 2014 at 10:53

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:09

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago

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