equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 |
26 |
27 package sun.nio.cs; |
27 package sun.nio.cs; |
28 |
28 |
29 import java.nio.*; |
|
30 import java.nio.charset.*; |
29 import java.nio.charset.*; |
31 |
30 |
32 |
31 |
33 /** |
32 /** |
34 * Utility class for caching per-thread decoders and encoders. |
33 * Utility class for caching per-thread decoders and encoders. |
39 private static final int CACHE_SIZE = 3; |
38 private static final int CACHE_SIZE = 3; |
40 |
39 |
41 private static abstract class Cache { |
40 private static abstract class Cache { |
42 |
41 |
43 // Thread-local reference to array of cached objects, in LRU order |
42 // Thread-local reference to array of cached objects, in LRU order |
44 private ThreadLocal cache = new ThreadLocal(); |
43 private ThreadLocal<Object[]> cache = new ThreadLocal<>(); |
45 private final int size; |
44 private final int size; |
46 |
45 |
47 Cache(int size) { |
46 Cache(int size) { |
48 this.size = size; |
47 this.size = size; |
49 } |
48 } |
58 } |
57 } |
59 |
58 |
60 abstract boolean hasName(Object ob, Object name); |
59 abstract boolean hasName(Object ob, Object name); |
61 |
60 |
62 Object forName(Object name) { |
61 Object forName(Object name) { |
63 Object[] oa = (Object[])cache.get(); |
62 Object[] oa = cache.get(); |
64 if (oa == null) { |
63 if (oa == null) { |
65 oa = new Object[size]; |
64 oa = new Object[size]; |
66 cache.set(oa); |
65 cache.set(oa); |
67 } else { |
66 } else { |
68 for (int i = 0; i < oa.length; i++) { |
67 for (int i = 0; i < oa.length; i++) { |