Providing JavaScript specific implementations of Hashtable and Vector. Those should likely be faster for the JavaScript VM than interpreting bytecode. This is the way to get the best of JavaScript and yet provide reasonably well working implementation in Java.
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package org.apidesign.javap;
7 import org.apidesign.bck2brwsr.core.JavaScriptBody;
9 /** A JavaScript optimized replacement for Hashtable.
11 * @author Jaroslav Tulach <jtulach@netbeans.org>
13 final class Hashtable {
14 private Object[] keys;
15 private Object[] values;
21 Hashtable(int i, double d) {
28 @JavaScriptBody(args = { "self", "key", "val" }, body =
31 synchronized void put(Object key, Object val) {
32 int[] where = { -1, -1 };
33 Object found = get(key, where);
36 values[where[0]] = val;
41 values[where[1]] = val;
44 keys = new Object[11];
45 values = new Object[11];
49 Object[] newKeys = new Object[keys.length * 2];
50 Object[] newValues = new Object[values.length * 2];
51 for (int i = 0; i < keys.length; i++) {
53 newValues[i] = values[i];
55 newKeys[keys.length] = key;
56 newValues[keys.length] = val;
64 @JavaScriptBody(args = {"self", "key" }, body =
67 Object get(Object key) {
68 return get(key, null);
70 private synchronized Object get(Object key, int[] foundAndNull) {
74 for (int i = 0; i < keys.length; i++) {
75 if (keys[i] == null) {
76 if (foundAndNull != null) {
79 } else if (keys[i].equals(key)) {
80 if (foundAndNull != null) {