Skip to content

Commit c40d424

Browse files
authored
Merge pull request #159 from BobHanson/hanson1
HashMap options allow switching off JavaScript Map in HashMap/Hashtable
2 parents ad93d6e + bbcaad1 commit c40d424

File tree

12 files changed

+45
-12
lines changed

12 files changed

+45
-12
lines changed
1.32 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200321064259
1+
20200321085805
1.32 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200321064259
1+
20200321085805

sources/net.sf.j2s.core/src/net/sf/j2s/core/CorePlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class CorePlugin extends Plugin {
3030
// if you change the x.x.x number, be sure to also indicate that in
3131
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3232

33+
// BH 2020.03.21 -- 3.2.9-v1e better v1c
34+
// BH 2020.03.20 -- 3.2.9-v1d proper check for new String("x") == "x" (should be false), but new integer(3) == 3 (true)
35+
// BH 2020.03.20 -- 3.2.9-v1c more efficient static call from 3.2.9-v1a
3336
// BH 2020.02.26 -- 3.2.9-v1b allows (byte) = (byte) to not use |0
3437
// BH 2020.02.20 -- 3.2.9-v1a reverses c,args order in new_(c,args,...) when both have expressions
3538
// BH 2020.02.18 -- 3.2.8-v2 fixes import static missing $I$ defs.
1.32 KB
Binary file not shown.

sources/net.sf.j2s.java.core/doc/Differences.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ new HashSet()
556556

557557
all use the JavaScript Map. But
558558

559-
new Hashtable(11, 0.75)
560-
new HashMap(16, 0.75)
561-
new HashSet(16, 0.75)
559+
new Hashtable(11, 0.75f)
560+
new HashMap(16, 0.75f)
561+
new HashSet(16, 0.75f)
562562

563563
do not.
564564

sources/net.sf.j2s.java.core/src/java/util/HashMap.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public class HashMap<K, V> extends AbstractMap<K, V> implements Map<K, V>, Clone
253253
static final int MIN_TREEIFY_CAPACITY = 64;
254254

255255
Map<String, Object> 秘m;
256+
boolean 秘allowJS = false;
256257

257258
/**
258259
* Basic hash bin node, used for most entries. (See below for TreeNode subclass,
@@ -421,6 +422,13 @@ static final int tableSizeFor(int cap) {
421422
*/
422423
final float loadFactor;
423424

425+
/**
426+
* flag developers can use to switch off all use of simple JavaScript Map objects
427+
*
428+
* not final, so that it can be managed on the fly in SwingJS
429+
*/
430+
public static boolean USE_SIMPLE = true;
431+
424432
/* ---------------- Public operations -------------- */
425433

426434
/**
@@ -456,6 +464,7 @@ public HashMap(int initialCapacity, float loadFactor) {
456464
*/
457465
public HashMap(int initialCapacity) {
458466
this(initialCapacity, DEFAULT_LOAD_FACTOR);
467+
秘allowJS = true;
459468
秘setJS();
460469
}
461470

@@ -466,6 +475,7 @@ public HashMap(int initialCapacity) {
466475
* and the default load factor (0.75).
467476
*/
468477
public HashMap() {
478+
秘allowJS = true;
469479
秘setJS();
470480
this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted
471481
}
@@ -480,6 +490,7 @@ public HashMap() {
480490
* @throws NullPointerException if the specified map is null
481491
*/
482492
public HashMap(Map<? extends K, ? extends V> m) {
493+
秘allowJS = (/** @j2sNative m.allowJS ||*/false);
483494
秘setJS();
484495
this.loadFactor = DEFAULT_LOAD_FACTOR;
485496
putMapEntries(m, false);
@@ -3067,7 +3078,7 @@ static <K, V> boolean checkInvariants(TreeNode<K, V> t) {
30673078

30683079
protected void 秘setJS() {
30693080

3070-
秘m = (Map.USE_SIMPLE ? /** @j2sNative new Map() || */
3081+
秘m = (秘allowJS && HashMap.USE_SIMPLE ? /** @j2sNative new Map() || */
30713082
null : null);
30723083
}
30733084

sources/net.sf.j2s.java.core/src/java/util/Hashtable.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class Hashtable<K,V>
130130
implements Map<K,V>, Cloneable, java.io.Serializable {
131131

132132
Map<String, Object> 秘m;
133+
boolean 秘allowJS = false;
133134

134135
/**
135136
* The hash table data.
@@ -204,6 +205,7 @@ public Hashtable(int initialCapacity, float loadFactor) {
204205
*/
205206
public Hashtable(int initialCapacity) {
206207
this(initialCapacity, 0.75f);
208+
秘allowJS = true;
207209
秘setJS();
208210
}
209211

@@ -215,6 +217,7 @@ public Hashtable(int initialCapacity) {
215217
*/
216218
public Hashtable() {
217219
this(11, 0.75f);
220+
秘allowJS = true;
218221
秘setJS();
219222
}
220223

@@ -229,6 +232,7 @@ public Hashtable() {
229232
*/
230233
public Hashtable(Map<? extends K, ? extends V> t) {
231234
this(Math.max(2*t.size(), 11), 0.75f);
235+
秘allowJS = (/** @j2sNative t.allowJS ||*/false);
232236
putAll(t);
233237
}
234238

@@ -1946,7 +1950,7 @@ public void remove() {
19461950
}
19471951

19481952
protected void 秘setJS() {
1949-
秘m = (Map.USE_SIMPLE ? /** @j2sNative new Map() || */
1953+
秘m = (秘allowJS && HashMap.USE_SIMPLE ? /** @j2sNative new Map() || */
19501954
null : null);
19511955
}
19521956

sources/net.sf.j2s.java.core/src/java/util/Map.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,11 +1200,6 @@ default V merge(K key, V value,
12001200
*/
12011201
}
12021202

1203-
/**
1204-
* flag developers can use to switch off all use of simple JavaScript Map objects
1205-
*/
1206-
static boolean USE_SIMPLE = true;
1207-
12081203
final static int NOT_SIMPLE = 0;
12091204
final static int INVALID_KEY = 1;
12101205
final static int NO_SUCH_KEY = 2;

0 commit comments

Comments
 (0)