Ignore:
Timestamp:
2015-07-05T22:14:49+02:00 (9 years ago)
Author:
bastiK
Message:

applied #11655 - memory optimization (patch by shinigami, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r8565 r8574  
    6666     */
    6767    public static synchronized Date fromString(String str) {
     68        return new Date(tsFromString(str));
     69    }
     70
     71    /**
     72     * Parses XML date quickly, regardless of current locale.
     73     * @param str The XML date as string
     74     * @return The date in milliseconds since epoch
     75     */
     76    public static synchronized long tsFromString(String str) {
    6877        // "2007-07-25T09:26:24{Z|{+|-}01:00}"
    6978        if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") ||
     
    8392                int plusHr = parsePart2(str, 20);
    8493                int mul = str.charAt(19) == '+' ? -3600000 : 3600000;
    85                 calendar.setTimeInMillis(calendar.getTimeInMillis()+plusHr*mul);
     94                return calendar.getTimeInMillis()+plusHr*mul;
    8695            }
    8796
    88             return calendar.getTime();
     97            return calendar.getTimeInMillis();
    8998        } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") ||
    9099                checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") ||
     
    99108                parsePart2(str, 17));
    100109            long millis = parsePart3(str, 20);
    101             if (str.length() == 29)
     110            if (str.length() == 29){
    102111                millis += parsePart2(str, 24) * (str.charAt(23) == '+' ? -3600000 : 3600000);
    103             calendar.setTimeInMillis(calendar.getTimeInMillis()+millis);
    104 
    105             return calendar.getTime();
     112            }
     113
     114            return calendar.getTimeInMillis() + millis;
    106115        } else {
    107116            // example date format "18-AUG-08 13:33:03"
     
    109118            Date d = f.parse(str, new ParsePosition(0));
    110119            if (d != null)
    111                 return d;
     120                return d.getTime();
    112121        }
    113122
    114123        try {
    115             return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTime();
     124            return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTimeInMillis();
    116125        } catch (Exception ex) {
    117             return new Date();
     126            return System.currentTimeMillis();
    118127        }
    119128    }
Note: See TracChangeset for help on using the changeset viewer.