Skip to content

Commit 63bfc38

Browse files
committed
Optimimizations for SwingJS runtime - Graphics2D, Rectangle,
BufferedImage, LineBorder, Path2D
1 parent 81bbdfd commit 63bfc38

File tree

16 files changed

+3214
-3159
lines changed

16 files changed

+3214
-3159
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231201065220
1+
20231210191429
-2.26 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231201065220
1+
20231210191429
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" path="src_4.2"/>
3+
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
55
<classpathentry kind="output" path="bin"/>
66
</classpath>
-548 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/awt/BasicStroke.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ public class BasicStroke implements Stroke, Cloneable {
150150
*/
151151
public final static int CAP_SQUARE = 2;
152152

153-
float width;
153+
final float width;
154154

155-
int join;
156-
int cap;
157-
float miterlimit;
155+
final int join;
156+
final int cap;
157+
final float miterlimit;
158158

159-
float dash[];
160-
float dash_phase;
159+
final float dash[];
160+
final float dash_phase;
161161

162162
/**
163163
* Constructs a new <code>BasicStroke</code> with the specified
@@ -223,9 +223,7 @@ public BasicStroke(float width, int cap, int join, float miterlimit,
223223
this.cap = cap;
224224
this.join = join;
225225
this.miterlimit = miterlimit;
226-
if (dash != null) {
227-
this.dash = (float []) dash.clone();
228-
}
226+
this.dash = (dash == null ? null : dash); // was .clone()
229227
this.dash_phase = dash_phase;
230228
}
231229

@@ -450,7 +448,9 @@ else if (bs.dash != null) {
450448

451449
@Override
452450
public Object clone() {
453-
return new BasicStroke(width, cap, join, miterlimit, dash, dash_phase);
451+
return this;
452+
// COULD THIS WORK??
453+
// return new BasicStroke(width, cap, join, miterlimit, dash, dash_phase);
454454
}
455455

456456

sources/net.sf.j2s.java.core/src/java/awt/Rectangle.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,19 @@ public boolean contains(Rectangle r) {
692692
* @since 1.1
693693
*/
694694
public boolean contains(int X, int Y, int W, int H) {
695-
int w = this.width;
696-
int h = this.height;
695+
return contains(this.x, this.y, this.width, this.height, X, Y, W, H);
696+
}
697+
698+
private static boolean contains(int tx, int ty, int tw, int th, int X, int Y, int W, int H) {
699+
int w = tw;
700+
int h = th;
697701
if ((w | h | W | H) < 0) {
698702
// At least one of the dimensions is negative...
699703
return false;
700704
}
701705
// Note: if any dimension is zero, tests below must return false...
702-
int x = this.x;
703-
int y = this.y;
706+
int x = tx;
707+
int y = ty;
704708
if (X < x || Y < y) {
705709
return false;
706710
}
@@ -726,7 +730,11 @@ public boolean contains(int X, int Y, int W, int H) {
726730
if (h >= y && H > h) return false;
727731
}
728732
return true;
729-
}
733+
}
734+
735+
public static boolean contains(int[] is, int X, int Y, int W, int H) {
736+
return contains(is[0], is[1], is[2], is[3], X, Y, W, H);
737+
}
730738

731739
/**
732740
* Checks whether or not this <code>Rectangle</code> contains the
@@ -1211,4 +1219,5 @@ public boolean equals(Object obj) {
12111219
public String toString() {
12121220
return getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]";
12131221
}
1222+
12141223
}

sources/net.sf.j2s.java.core/src/java/awt/geom/Path2D.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ void append(double x, double y) {
307307
floatCoords[numCoords++] = (float) y;
308308
}
309309

310+
public void clear() {
311+
numCoords = 0;
312+
}
310313
/**
311314
* {@inheritDoc}
312315
* @since 1.6
@@ -2447,6 +2450,7 @@ public PathIterator getPathIterator(AffineTransform at,
24472450
// compatibility so we cannot restrict it further.
24482451
// REMIND: Can we do both somehow?
24492452

2453+
24502454
// /*
24512455
// * Support fields and methods for serializing the subclasses.
24522456
// */

sources/net.sf.j2s.java.core/src/java/io/File.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,8 @@ public int hashCode() {
19591959
*/
19601960
@Override
19611961
public String toString() {
1962-
return getPath();
1962+
String s = getPath();
1963+
return (s.startsWith("./") ? s.substring(2) : s);
19631964
}
19641965

19651966
public Path toPath() {

0 commit comments

Comments
 (0)