Thanks Roger,

Updated the webrev based on thebelow suggested changes and some clean up.

http://cr.openjdk.java.net/~nishjain/8177552/webrevs/webrev.05/

On 01-12-2018 01:03, Roger Riggs wrote:
Hi Nishit,

Some comments, a couple of possible bugs and several  performance related issues could be deferred. Both formatting and parsing seem to be quite heavyweight
due to looping and combinatorics.


CompactNumberFormat.java


661, 727, 1507: Is there a reason to convert the divisor to a string and then re-parse it to create a new BigDecimal?         (IntelliJ observes that divide is called without a rounding argument.)         Given that the divisors are all powers of 10 and the digit list is a base 10 set of digits         it seems more efficient to just move the decimal point then to do the math.         BTW, the divisor.toString() is preferred over concat with "".  (looks like a hack).

        It would be more efficient to write two methods that would pass the Number         and return a BigInteger or BigDecimal by dispatching on the concrete type and
        using the appropriate constructor.
Changed concatenation with toString() and added a rounding parameter, but not getting the benefit of having two methods and returning respective concrete type using constructors.
I didn't get the point of having two methods. Can you please elaborate?

781:  @param prefix - the parameter name is suffix

804: move the int start = inside the if.

826:  expandAffix can be more efficient if tests the pattern for the presence of QUOTE         and returns the pattern if the QUOTE is not present.  That would be the most common case.

914: Reduce the number of compares by reordering to:
        if number > currentValue; multiply and continue
        if number < currentValue break;
        else ==; assign matched index and break;

        In the normal case, there will be only one compare in the loop until it is to exit.

1109:  IntelliJ observes that within the case QUOTE, the if (ch == QUOTE) is always true
      so the if is redundant.
OK.

1205:  It looks odd to prepend two characters '- to the prefix. Is the single quote correct?
      Where's the closing quote if so.
It is to specify that the minus sign is a special character, which needs to be replaced with its localized equivalent at the time of formatting.

Internally, there is a difference between a "minus sign prefix with a single quote" and a "minus sign" (it depends on how user specify the pattern), because the later one is considered as a literal and should be used exactly same in the formatted output, but the one prefixed with a single quote is replaced with its localized symbol using DecimalFormatSymbols.getMinusSign().

1394: matchedPosPrefix.length() is compared to negativePrefix.length().
      That's an unusual mixing of positive and negative! Please re-check.
Yes, it was a mistake.

1363:  Can there be an early exit from this loop if one of the prefixes is identified?       The pattern of comparing for a prefix/suffix and the length might warrant       creating a private method to reduce the repetitive parts of the code.
I had thought about it, but it was difficult unless the whole list of affixes are traversed, because there is always a chance to get longer affix later in the list. I thought to sort the lists based on the length and do the match, but in that case indexes get disordered across lists (divisor, prefix, suffix, compact patterns), and computation will become more complicated. Updated the code by moving the repetitive parts in the loop to private methods.

1593: extra space between "- ("; should be the same style as 1591

1627, 1363: Is an early exit from this loop possible?
       or a quick comparison to avoid the regionMatches.
       Do the regionMatches *only if* the prefix/suffix is longer than the suffix already compared?
Yes, I think this can be done. Updated.

1721:  IntelliJ observes that if (gotNeg) is redundant since 1708 rules out them being both true or both false.
Updated

Regards,
Nishit Jain

Thanks, Roger


On 11/28/18 3:46 AM, Nishit Jain wrote:
Thanks Naoto,

Updated.

http://cr.openjdk.java.net/~nishjain/8177552/webrevs/webrev.04/



Reply via email to