Lines 83-88
Link Here
|
83 |
private Object js; |
83 |
private Object js; |
84 |
private Object strong; |
84 |
private Object strong; |
85 |
|
85 |
|
|
|
86 |
private static int cntCreated; |
87 |
private static int cntCleaned; |
88 |
private static long cntLast = System.currentTimeMillis(); |
89 |
|
86 |
public Knockout(Object model, Object js, PropertyBinding[] props, FunctionBinding[] funcs) { |
90 |
public Knockout(Object model, Object js, PropertyBinding[] props, FunctionBinding[] funcs) { |
87 |
super(model, QUEUE); |
91 |
super(model, QUEUE); |
88 |
this.js = js; |
92 |
this.js = js; |
Lines 95-100
Link Here
|
95 |
this.funcs[i] = funcs[i].weak(); |
99 |
this.funcs[i] = funcs[i].weak(); |
96 |
} |
100 |
} |
97 |
active.add(this); |
101 |
active.add(this); |
|
|
102 |
cntCreated++; |
98 |
} |
103 |
} |
99 |
|
104 |
|
100 |
static void cleanUp() { |
105 |
static void cleanUp() { |
Lines 103-108
Link Here
|
103 |
if (ko == null) { |
108 |
if (ko == null) { |
104 |
return; |
109 |
return; |
105 |
} |
110 |
} |
|
|
111 |
cntCleaned++; |
112 |
if (cntLast + 1000 > System.currentTimeMillis()) { |
113 |
cntLast = System.currentTimeMillis(); |
114 |
System.err.printf("Java created %d vs. cleaned %d\n", cntCreated, cntCleaned); |
115 |
} |
106 |
active.remove(ko); |
116 |
active.remove(ko); |
107 |
clean(ko.js); |
117 |
clean(ko.js); |
108 |
ko.js = null; |
118 |
ko.js = null; |
Lines 159-166
Link Here
|
159 |
|
169 |
|
160 |
@JavaScriptBody(args = { "cnt" }, body = |
170 |
@JavaScriptBody(args = { "cnt" }, body = |
161 |
"var arr = new Array(cnt);\n" + |
171 |
"var arr = new Array(cnt);\n" + |
162 |
"for (var i = 0; i < cnt; i++) arr[i] = new Object();\n" + |
172 |
"var pool = window.pool;\n" + |
163 |
"return arr;\n" |
173 |
"if (!pool) {\n" + |
|
|
174 |
" pool = window.pool = [];\n" + |
175 |
" pool.cntNew = 0;\n" + |
176 |
" pool.cntPush = 0;\n" + |
177 |
" pool.cntPop = 0;\n" + |
178 |
" for (var i = 0; i < 1000000; i++) {\n" + |
179 |
" pool.push(new Object())\n" + |
180 |
" }\n" + |
181 |
"}\n" + |
182 |
"for (var i = 0; i < cnt; i++) {\n" + |
183 |
" if (pool.length > 0) {\n" + |
184 |
" arr[i] = pool.pop();\n" + |
185 |
" pool.cntPop++;\n" + |
186 |
" } else {\n" + |
187 |
" pool.cntNew++;\n" + |
188 |
" arr[i] = new Object();\n" + |
189 |
" }\n" + |
190 |
" if ((pool.cntNew + pool.cntPop + pool.cntPush) % 1000 == 0) {\n" + |
191 |
// " console.log('New: ' + pool.cntNew + ' pop: ' + pool.cntPop + ' push: ' + pool.cntPush);\n" + |
192 |
" }\n" + |
193 |
"}\n" |
194 |
+ "return arr;\n" |
164 |
) |
195 |
) |
165 |
native static Object[] allocJS(int cnt); |
196 |
native static Object[] allocJS(int cnt); |
166 |
|
197 |
|
Lines 170-176
Link Here
|
170 |
wait4js = false, |
201 |
wait4js = false, |
171 |
args = { "ret", "copyFrom", "propNames", "propInfo", "propValues", "funcNames" }, |
202 |
args = { "ret", "copyFrom", "propNames", "propInfo", "propValues", "funcNames" }, |
172 |
body = |
203 |
body = |
173 |
"Object.defineProperty(ret, 'ko4j', { value : this });\n" |
204 |
"Object.defineProperty(ret, 'ko4j', { value : this, writable : true, configurable : true });\n" |
174 |
+ "function normalValue(r) {\n" |
205 |
+ "function normalValue(r) {\n" |
175 |
+ " if (r) try { var br = r.valueOf(); } catch (err) {}\n" |
206 |
+ " if (r) try { var br = r.valueOf(); } catch (err) {}\n" |
176 |
+ " return br === undefined ? r: br;\n" |
207 |
+ " return br === undefined ? r: br;\n" |
Lines 257-262
Link Here
|
257 |
"for (var p in js) {\n" + |
288 |
"for (var p in js) {\n" + |
258 |
" delete js[p];\n" + |
289 |
" delete js[p];\n" + |
259 |
"};\n" + |
290 |
"};\n" + |
|
|
291 |
"window.pool.cntPush++;\n" + |
292 |
"window.pool.push(js);\n" + |
260 |
"\n" |
293 |
"\n" |
261 |
) |
294 |
) |
262 |
private static native void clean(Object js); |
295 |
private static native void clean(Object js); |