You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2019/02/15 19:57:35 UTC
[incubator-netbeans-html4j] 12/15: Use round-robin cache
This is an automated email from the ASF dual-hosted git repository.
jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git
commit 68228faeff77a74649e2076f1cb504c35aca8bf2
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Thu Feb 14 19:02:17 2019 +0100
Use round-robin cache
---
.../java/org/netbeans/html/ko4j/CacheObjs.java | 54 +++++++---------------
1 file changed, 17 insertions(+), 37 deletions(-)
diff --git a/ko4j/src/main/java/org/netbeans/html/ko4j/CacheObjs.java b/ko4j/src/main/java/org/netbeans/html/ko4j/CacheObjs.java
index 6311ff2..4da77c2 100644
--- a/ko4j/src/main/java/org/netbeans/html/ko4j/CacheObjs.java
+++ b/ko4j/src/main/java/org/netbeans/html/ko4j/CacheObjs.java
@@ -19,56 +19,36 @@
package org.netbeans.html.ko4j;
-import java.lang.ref.WeakReference;
import org.netbeans.html.boot.spi.Fn;
-final class CacheObjs extends WeakReference<Fn.Presenter> {
+final class CacheObjs {
/* both @GuardedBy CacheObjs.class */
- private static CacheObjs list;
- private CacheObjs next;
+ private static CacheObjs[] list = new CacheObjs[16];
+ private static int listAt = 0;
+ private final Fn.Presenter ref;
/* both @GuardedBy presenter single threaded access */
private Object[] jsObjects;
private int jsIndex;
- private CacheObjs(CacheObjs next, Fn.Presenter p) {
- super(p);
- this.next = next;
+ private CacheObjs(Fn.Presenter p) {
+ this.ref = p;
}
- static synchronized CacheObjs find(Fn.Presenter key) {
- if (list == null) {
- return list = new CacheObjs(null, key);
- }
-
- Fn.Presenter p;
- for (;;) {
- p = list.get();
- if (p != null) {
- break;
- }
- list = list.next;
- }
-
- if (p == key) {
- return list;
- }
-
- CacheObjs prev = list;
- CacheObjs now = list.next;
+ Fn.Presenter get() {
+ return ref;
+ }
- while (now != null) {
- p = now.get();
- if (p == null) {
- prev.next = now;
- }
- if (p == key) {
- return now;
+ static synchronized CacheObjs find(Fn.Presenter key) {
+ for (int i = 0; i < list.length; i++) {
+ if (list[i] != null && list[i].get() == key) {
+ return list[i];
}
- prev = now;
- now = now.next;
}
- return prev.next = new CacheObjs(null, key);
+ CacheObjs co = new CacheObjs(key);
+ list[listAt] = co;
+ listAt = (listAt + 1) % list.length;
+ return co;
}
Object getJSObject() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists