Changeset 8565 in josm


Ignore:
Timestamp:
2015-07-04T18:31:20+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #11650 - performance: avoid creation of Date objects when it is not needed (patch by shinigami, modified slightly)

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r8512 r8565  
    567567
    568568                if ("timestamp".equals(key)) {
    569                     mv = DateUtils.fromDate(osm.getTimestamp());
     569                    mv = DateUtils.fromTimestamp(osm.getRawTimestamp());
    570570                } else {
    571571                    mv = osm.get(key);
     
    10871087        @Override
    10881088        protected Long getNumber(OsmPrimitive osm) {
    1089             return osm.getTimestamp().getTime();
     1089            return osm.getRawTimestamp() * 1000L;
    10901090        }
    10911091
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r8540 r8565  
    292292    }
    293293
     294    @Override
     295    public void setRawTimestamp(int timestamp) {
     296        this.timestamp = timestamp;
     297    }
     298
    294299    /**
    295300     * Time of last modification to this object. This is not set by JOSM but
     
    302307    public Date getTimestamp() {
    303308        return new Date(timestamp * 1000L);
     309    }
     310
     311    @Override
     312    public int getRawTimestamp() {
     313        return timestamp;
    304314    }
    305315
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r8540 r8565  
    100100                    target.setVisible(source.isVisible());
    101101                    target.setUser(source.getUser());
    102                     target.setTimestamp(source.getTimestamp());
     102                    target.setRawTimestamp(source.getRawTimestamp());
    103103                    target.setModified(source.isModified());
    104104                    objectsWithChildrenToMerge.add(source.getPrimitiveId());
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r8510 r8565  
    4141    Date getTimestamp();
    4242
     43    int getRawTimestamp();
     44
    4345    void setTimestamp(Date timestamp);
     46
     47    void setRawTimestamp(int timestamp);
    4448
    4549    boolean isTimestampEmpty();
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r8510 r8565  
    12281228        // Write lock is provided by subclasses
    12291229        setKeys(data.getKeys());
    1230         setTimestamp(data.getTimestamp());
     1230        setRawTimestamp(data.getRawTimestamp());
    12311231        user = data.getUser();
    12321232        setChangesetId(data.getChangesetId());
     
    12501250        data.setId(id);
    12511251        data.setKeys(getKeys());
    1252         data.setTimestamp(getTimestamp());
     1252        data.setRawTimestamp(getRawTimestamp());
    12531253        data.setUser(user);
    12541254        data.setDeleted(isDeleted());
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r8498 r8565  
    233233            add(tr("Data Set: "), Integer.toHexString(o.getDataSet().hashCode()));
    234234            add(tr("Edited at: "), o.isTimestampEmpty() ? tr("<new object>")
    235                     : DateUtils.fromDate(o.getTimestamp()));
     235                    : DateUtils.fromTimestamp(o.getRawTimestamp()));
    236236            add(tr("Edited by: "), o.getUser() == null ? tr("<new object>")
    237237                    : getNameAndId(o.getUser().getName(), o.getUser().getId()));
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r8540 r8565  
    597597
    598598        if (!n.isTimestampEmpty()) {
    599             wpt.put("time", DateUtils.fromDate(n.getTimestamp()));
     599            wpt.put("time", DateUtils.fromTimestamp(n.getRawTimestamp()));
    600600            wpt.setTime();
    601601        }
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r8510 r8565  
    299299            }
    300300            if (!osm.isTimestampEmpty()) {
    301                 out.print(" timestamp='"+DateUtils.fromDate(osm.getTimestamp())+"'");
     301                out.print(" timestamp='"+DateUtils.fromTimestamp(osm.getRawTimestamp())+"'");
    302302            }
    303303            // user and visible added with 0.4 API
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r8564 r8565  
    119119    }
    120120
     121    private static String toXmlFormat(GregorianCalendar cal) {
     122        XMLGregorianCalendar xgc = XML_DATE.newXMLGregorianCalendar(cal);
     123        if (cal.get(Calendar.MILLISECOND) == 0) {
     124            xgc.setFractionalSecond(null);
     125        }
     126        return xgc.toXMLFormat();
     127    }
     128
     129    /**
     130     * Formats a date to the XML UTC format regardless of current locale.
     131     * @param timestamp number of seconds since the epoch
     132     * @return The formatted date
     133     */
     134    public static synchronized String fromTimestamp(int timestamp) {
     135        calendar.setTimeInMillis(timestamp * 1000L);
     136        return toXmlFormat(calendar);
     137    }
     138
    121139    /**
    122140     * Formats a date to the XML UTC format regardless of current locale.
     
    126144    public static synchronized String fromDate(Date date) {
    127145        calendar.setTime(date);
    128         XMLGregorianCalendar xgc = XML_DATE.newXMLGregorianCalendar(calendar);
    129         if (calendar.get(Calendar.MILLISECOND) == 0) xgc.setFractionalSecond(null);
    130         return xgc.toXMLFormat();
     146        return toXmlFormat(calendar);
    131147    }
    132148
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java

    r8510 r8565  
    317317        their.addPrimitive(n1);
    318318
    319 
    320319        DataSetMerger visitor = new DataSetMerger(my, their);
    321320        visitor.merge();
     
    324323        assertEquals(0, visitor.getConflicts().size());
    325324        assertEquals("value1", n2.get("key1"));
    326         assertTrue(n1.getTimestamp().equals(n2.getTimestamp()));
     325        assertEquals(n1.getRawTimestamp(), n2.getRawTimestamp());
    327326        assertEquals(theirUser, n2.getUser());
    328327        assertSame(n2, n);
     
    351350        their.addPrimitive(n1);
    352351
    353 
    354352        DataSetMerger visitor = new DataSetMerger(my, their);
    355353        visitor.merge();
     
    358356        assertEquals(0, visitor.getConflicts().size());
    359357        assertEquals("value1", n2.get("key1"));
    360         assertTrue(n1.getTimestamp().equals(n2.getTimestamp()));
     358        assertEquals(n1.getRawTimestamp(), n2.getRawTimestamp());
    361359        assertFalse(n2.isIncomplete());
    362360        assertSame(n2, n);
     
    665663        assertEquals("their", merged.getUser().getName());
    666664        assertEquals(1111, merged.getUser().getId());
    667         assertEquals(theirWay.getTimestamp(), merged.getTimestamp());
     665        assertEquals(theirWay.getRawTimestamp(), merged.getRawTimestamp());
    668666        assertSame(merged, myWay);
    669667        assertSame(merged.getNode(0), n1);
     
    719717        assertEquals("their", merged.getUser().getName());
    720718        assertEquals(1111, merged.getUser().getId());
    721         assertEquals(theirWay.getTimestamp(), merged.getTimestamp());
     719        assertEquals(theirWay.getRawTimestamp(), merged.getRawTimestamp());
    722720        assertSame(merged, myWay);
    723721        assertSame(merged.getNode(0), n1);
Note: See TracChangeset for help on using the changeset viewer.