Small improvement for FixedMillisecond

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Small improvement for FixedMillisecond

Post by uvoigt » Tue Aug 19, 2014 9:01 am

Hi David,

I observed that the constructor FixedMillisecond(long) creates a Date object to retrieve the original long value. From my point of view this is not necessary. Although the objects are temporary only it should be faster not to create them.
Please find a patch below.

Ulrich

Code: Select all

### Eclipse Workspace Patch 1.0
#P JFree_ORG
Index: source/org/jfree/data/time/FixedMillisecond.java
===================================================================
--- source/org/jfree/data/time/FixedMillisecond.java	(revision 3296)
+++ source/org/jfree/data/time/FixedMillisecond.java	(working copy)
@@ -65,7 +65,7 @@
     private static final long serialVersionUID = 7867521484545646931L;
 
     /** The millisecond. */
-    private long time;
+    private final long time;
 
     /**
      * Constructs a millisecond based on the current system time.
@@ -80,7 +80,7 @@
      * @param millisecond  the millisecond (same encoding as java.util.Date).
      */
     public FixedMillisecond(long millisecond) {
-        this(new Date(millisecond));
+        this.time = millisecond;
     }
 
     /**
@@ -89,7 +89,7 @@
      * @param time  the time.
      */
     public FixedMillisecond(Date time) {
-        this.time = time.getTime();
+        this(time.getTime());
     }
 
     /**

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Small improvement for FixedMillisecond

Post by david.gilbert » Fri Aug 22, 2014 6:22 pm

Good suggestion thanks. I committed the change for inclusion in the 1.0.20 release.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked