You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2011/05/18 15:53:57 UTC

[LANG] unnecessary boxing in StringEscapeUtils etc.

I'm not happy with the boxing that is often needed to create a Range
of int or long, e.g. in StringEscapeUtils.

Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
should require ints rather than a Range, as this would cut down on the
boxing and unboxing that is currently needed, as well as the extra
code needed to provide comparisons etc.

Or, there could be a specialised IntRange class using int to provide
the functionality.

These changes are new to 3.0, so could be fixed now without backward
compat. problems.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Henri Yandell <fl...@gmail.com>.
On Thu, May 19, 2011 at 6:30 AM, Gary Gregory <ga...@gmail.com> wrote:
> On Thu, May 19, 2011 at 12:47 AM, Henri Yandell <fl...@gmail.com> wrote:
>
>> *grumbles that they were ints and a previous RC candidate saw it
>> change to Range* :)
>>
>
>
> Change it back! ;)

Tongue in cheek as it might be, I think this is the right direction.

Forcing it onto the Range API made it less useable, so best to stay
with the original more useable code even if it implies some redundancy
code-wise.

It might imply that we need subclasses to Ranges; but I think int and
char are a wee bit special and it's no reason to doubt the Range
class.

I've rolled back the commit:

svn ci -m "Reverting r1090111 - moving the text.translate escapers
back from using Range to replicating parts of the Range API. See the
list for details ('unnecessary boxing in StringEscapeUtils etc'), the
move to Range was an uncomfortable fit. "

Sending        src/main/java/org/apache/commons/lang3/StringEscapeUtils.java
Sending        src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
Sending        src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
Sending        src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
Sending        src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
Transmitting file data .....
Committed revision 1142151.


Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Gary Gregory <ga...@gmail.com>.
On Thu, May 19, 2011 at 12:47 AM, Henri Yandell <fl...@gmail.com> wrote:

> *grumbles that they were ints and a previous RC candidate saw it
> change to Range* :)
>


Change it back! ;)

Gary


>
> My bigger complaint is the explicit casting required to pass in chars:
>
>    new UnicodeEscaper(Range.between(0, (int)'E')) ?
>
> Autoboxing doesn't seem to be able to turn a char into an Integer.
>
> Hen
>
> On Wed, May 18, 2011 at 6:53 AM, sebb <se...@gmail.com> wrote:
> > I'm not happy with the boxing that is often needed to create a Range
> > of int or long, e.g. in StringEscapeUtils.
> >
> > Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
> > should require ints rather than a Range, as this would cut down on the
> > boxing and unboxing that is currently needed, as well as the extra
> > code needed to provide comparisons etc.
> >
> > Or, there could be a specialised IntRange class using int to provide
> > the functionality.
> >
> > These changes are new to 3.0, so could be fixed now without backward
> > compat. problems.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
Thank you,
Gary

http://garygregory.wordpress.com/
http://garygregory.com/
http://people.apache.org/~ggregory/
http://twitter.com/GaryGregory

Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Matt Benson <gu...@gmail.com>.
On Thu, May 19, 2011 at 5:14 AM, Stephen Colebourne
<sc...@joda.org> wrote:
> I doubt that the boxing will be a major performance problem. Moreover,
> its one that will have to be solved for JDK 8 anyway (as Project
> Lambda needs some kind of solution to enhance primitive/object
> operations).
>

I'd prefer to see this left alone.  As Hen mentions on another thread,
this isn't the biggest part of the lang APIs, and the consistency of a
single Range type is appealing, especially if autoboxing woes are
slated to be ameliorated in the not-too-distant future.

HOWEVER, if we prefer to have the ability to optimize around these
autoboxing complaints, why don't we add a level of inheritance to the
CodePointTranslator taxonomy, wherein we place the "is this an
applicable codepoint" check and delegate that to another interface?
Now a specialized IntRange can be supplied after all, and can use a
corresponding "CodepointInclusionPredicate" implementation to make the
proper call.  Optimizable, but works out of the box using autoboxing.

> If the cast is a problem, why not have four versions of the operation
> - Integer, Char, int and char?
> That means that any optimisation for primitives can be handled
> internally in a non-breaking way at a later date.
>

Sounds reasonable.

Matt

> Stephen
>
>
> On 19 May 2011 05:47, Henri Yandell <fl...@gmail.com> wrote:
>> *grumbles that they were ints and a previous RC candidate saw it
>> change to Range* :)
>>
>> My bigger complaint is the explicit casting required to pass in chars:
>>
>>    new UnicodeEscaper(Range.between(0, (int)'E')) ?
>>
>> Autoboxing doesn't seem to be able to turn a char into an Integer.
>>
>> Hen
>>
>> On Wed, May 18, 2011 at 6:53 AM, sebb <se...@gmail.com> wrote:
>>> I'm not happy with the boxing that is often needed to create a Range
>>> of int or long, e.g. in StringEscapeUtils.
>>>
>>> Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
>>> should require ints rather than a Range, as this would cut down on the
>>> boxing and unboxing that is currently needed, as well as the extra
>>> code needed to provide comparisons etc.
>>>
>>> Or, there could be a specialised IntRange class using int to provide
>>> the functionality.
>>>
>>> These changes are new to 3.0, so could be fixed now without backward
>>> compat. problems.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Stephen Colebourne <sc...@joda.org>.
I doubt that the boxing will be a major performance problem. Moreover,
its one that will have to be solved for JDK 8 anyway (as Project
Lambda needs some kind of solution to enhance primitive/object
operations).

If the cast is a problem, why not have four versions of the operation
- Integer, Char, int and char?
That means that any optimisation for primitives can be handled
internally in a non-breaking way at a later date.

Stephen


On 19 May 2011 05:47, Henri Yandell <fl...@gmail.com> wrote:
> *grumbles that they were ints and a previous RC candidate saw it
> change to Range* :)
>
> My bigger complaint is the explicit casting required to pass in chars:
>
>    new UnicodeEscaper(Range.between(0, (int)'E')) ?
>
> Autoboxing doesn't seem to be able to turn a char into an Integer.
>
> Hen
>
> On Wed, May 18, 2011 at 6:53 AM, sebb <se...@gmail.com> wrote:
>> I'm not happy with the boxing that is often needed to create a Range
>> of int or long, e.g. in StringEscapeUtils.
>>
>> Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
>> should require ints rather than a Range, as this would cut down on the
>> boxing and unboxing that is currently needed, as well as the extra
>> code needed to provide comparisons etc.
>>
>> Or, there could be a specialised IntRange class using int to provide
>> the functionality.
>>
>> These changes are new to 3.0, so could be fixed now without backward
>> compat. problems.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Henri Yandell <fl...@gmail.com>.
*grumbles that they were ints and a previous RC candidate saw it
change to Range* :)

My bigger complaint is the explicit casting required to pass in chars:

    new UnicodeEscaper(Range.between(0, (int)'E')) ?

Autoboxing doesn't seem to be able to turn a char into an Integer.

Hen

On Wed, May 18, 2011 at 6:53 AM, sebb <se...@gmail.com> wrote:
> I'm not happy with the boxing that is often needed to create a Range
> of int or long, e.g. in StringEscapeUtils.
>
> Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
> should require ints rather than a Range, as this would cut down on the
> boxing and unboxing that is currently needed, as well as the extra
> code needed to provide comparisons etc.
>
> Or, there could be a specialised IntRange class using int to provide
> the functionality.
>
> These changes are new to 3.0, so could be fixed now without backward
> compat. problems.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Gary Gregory <ga...@gmail.com>.
In the same vein, we've agreed that Pair should not be final, and so if we
keep Range, is should not be final either.

Gary

On Wed, May 18, 2011 at 11:37 AM, Gary Gregory <ga...@gmail.com>wrote:

> The bigger issue in my mind is why a Range does not extend Pair. It's
> pretty clear (to me at least) that a range is a pair of values.
>
> Because the Pair is in our tuple package, it means that it should follow
> tuple logic and be an ordered list of elements, in this case two elements.
>
> This means that the methods that Range has that are not in Pair could be
> moved there.
>
> Gary
>
>
> On Wed, May 18, 2011 at 9:53 AM, sebb <se...@gmail.com> wrote:
>
>> I'm not happy with the boxing that is often needed to create a Range
>> of int or long, e.g. in StringEscapeUtils.
>>
>> Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
>> should require ints rather than a Range, as this would cut down on the
>> boxing and unboxing that is currently needed, as well as the extra
>> code needed to provide comparisons etc.
>>
>> Or, there could be a specialised IntRange class using int to provide
>> the functionality.
>>
>> These changes are new to 3.0, so could be fixed now without backward
>> compat. problems.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> --
> Thank you,
> Gary
>
> http://garygregory.wordpress.com/
> http://garygregory.com/
> http://people.apache.org/~ggregory/
> http://twitter.com/GaryGregory
>



-- 
Thank you,
Gary

http://garygregory.wordpress.com/
http://garygregory.com/
http://people.apache.org/~ggregory/
http://twitter.com/GaryGregory

Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by sebb <se...@gmail.com>.
On 18 May 2011 16:37, Gary Gregory <ga...@gmail.com> wrote:
> The bigger issue in my mind is why a Range does not extend Pair. It's pretty
> clear (to me at least) that a range is a pair of values.

Please start a new thread for that issue.

AFAICT that would not help improve the performance of the Escaper
classes and the utility classes that call them.

> Because the Pair is in our tuple package, it means that it should follow
> tuple logic and be an ordered list of elements, in this case two elements.
>
> This means that the methods that Range has that are not in Pair could be
> moved there.
>
> Gary
>
> On Wed, May 18, 2011 at 9:53 AM, sebb <se...@gmail.com> wrote:
>
>> I'm not happy with the boxing that is often needed to create a Range
>> of int or long, e.g. in StringEscapeUtils.
>>
>> Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
>> should require ints rather than a Range, as this would cut down on the
>> boxing and unboxing that is currently needed, as well as the extra
>> code needed to provide comparisons etc.
>>
>> Or, there could be a specialised IntRange class using int to provide
>> the functionality.
>>
>> These changes are new to 3.0, so could be fixed now without backward
>> compat. problems.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> --
> Thank you,
> Gary
>
> http://garygregory.wordpress.com/
> http://garygregory.com/
> http://people.apache.org/~ggregory/
> http://twitter.com/GaryGregory
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by James Ring <sj...@jdns.org>.
Hey,

On Wed, May 18, 2011 at 8:37 AM, Gary Gregory <ga...@gmail.com> wrote:
> The bigger issue in my mind is why a Range does not extend Pair. It's pretty
> clear (to me at least) that a range is a pair of values.

Mathematically speaking a Range also has information about whether the
high and low bounds are inclusive or exclusive... but commons lang
Ranges are always inclusive so I guess it's not concerned with that
and can be treated as just a pair.

> Because the Pair is in our tuple package, it means that it should follow
> tuple logic and be an ordered list of elements, in this case two elements.
>
> This means that the methods that Range has that are not in Pair could be
> moved there.
>
> Gary

Regards,
James

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] unnecessary boxing in StringEscapeUtils etc.

Posted by Gary Gregory <ga...@gmail.com>.
The bigger issue in my mind is why a Range does not extend Pair. It's pretty
clear (to me at least) that a range is a pair of values.

Because the Pair is in our tuple package, it means that it should follow
tuple logic and be an ordered list of elements, in this case two elements.

This means that the methods that Range has that are not in Pair could be
moved there.

Gary

On Wed, May 18, 2011 at 9:53 AM, sebb <se...@gmail.com> wrote:

> I'm not happy with the boxing that is often needed to create a Range
> of int or long, e.g. in StringEscapeUtils.
>
> Seems to me that the UnicodeEscaper and NumericEntityEscaper classes
> should require ints rather than a Range, as this would cut down on the
> boxing and unboxing that is currently needed, as well as the extra
> code needed to provide comparisons etc.
>
> Or, there could be a specialised IntRange class using int to provide
> the functionality.
>
> These changes are new to 3.0, so could be fixed now without backward
> compat. problems.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
Thank you,
Gary

http://garygregory.wordpress.com/
http://garygregory.com/
http://people.apache.org/~ggregory/
http://twitter.com/GaryGregory