Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5574#discussion_r28738683
  
    --- Diff: 
network/common/src/main/java/org/apache/spark/network/util/JavaUtils.java ---
    @@ -186,5 +196,80 @@ public static long timeStringAsMs(String str) {
       public static long timeStringAsSec(String str) {
         return parseTimeString(str, TimeUnit.SECONDS);
       }
    +  
    +  /**
    +   * Convert a passed byte string (e.g. 50b, 100kb, or 250mb) to a 
ByteUnit for
    +   * internal use. If no suffix is provided a direct conversion of the 
provided default is 
    +   * attempted.
    +   */
    +  private static long parseByteString(String str, ByteUnit unit) {
    +    String lower = str.toLowerCase().trim();
     
    +    try {
    +      String suffix;
    +      long val;
    +      Matcher m = Pattern.compile("([0-9]+)([a-z]+)?").matcher(lower);
    +      if (m.matches()) {
    +        val = Long.parseLong(m.group(1));
    +        suffix = m.group(2);
    +      } else {
    +        throw new NumberFormatException("Failed to parse byte string: " + 
str);
    +      }
    +
    +      // Check for invalid suffixes
    +      if (suffix != null && !byteSuffixes.containsKey(suffix)) {
    +        throw new NumberFormatException("Invalid suffix: \"" + suffix + 
"\"");
    +      }
    +
    +      // If suffix is valid use that, otherwise none was provided and use 
the default passed
    +      return new Double(
    --- End diff --
    
    Why `new Double`? Not only it looks unnecessary but you're reducing the 
range of the result (double = 53 bits vs. long = 64 bits).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to