Le 12/04/12 10:57, Benedict Elliott Smith a écrit :
I think in this case it is reasonable to leave it to the user to ensure
that the input remains consistent for the duration of the call. It can be
documented if necessary, but as I say I think all imperative methods come
with that caveat by definition. Calling the toString() method as a solution
is really no better than asking the user to do the same, albeit a little
neater; the only reason a CharSequence method would be preferred is that
you can avoid unnecessary object allocation. For a very lightweight method
like parseInt, this can dramatically reduce the impact of making the call.

We faced this issue in our project when parsing OpenStreetMap data (an open source alternative to Google Map). The amount of integers to parse is so large that the calls to the 'toString()' method has been identified as a significant bottleneck by the NetBeans profiler. We tried a copy of the 'parseInt' method with the String argument replaced by CharSequence, and noticed a significant performance gain.

    Martin

Reply via email to