• R/O
  • SSH
  • HTTPS

jsonic: コミット


コミットメタ情報

リビジョン1839 (tree)
日時2014-09-13 10:26:10
作者hizuno

ログメッセージ

(メッセージはありません)

変更サマリ

差分

--- trunk/jsonic-1.3/src/net/arnx/jsonic/util/LocalCache.java (revision 1838)
+++ trunk/jsonic-1.3/src/net/arnx/jsonic/util/LocalCache.java (revision 1839)
@@ -1,12 +1,12 @@
1-/*
1+/*
22 * Copyright 2014 Hidekatsu Izuno
3- *
3+ *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- *
7+ *
88 * http://www.apache.org/licenses/LICENSE-2.0
9- *
9+ *
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,23 +29,24 @@
2929
3030 public class LocalCache {
3131 private static final int CACHE_SIZE = 256;
32-
32+
3333 private ResourceBundle resources;
3434 private Locale locale;
3535 private TimeZone timeZone;
36-
36+
3737 private StringBuilder builderCache;
38+ private int stringCacheCount = 0;
3839 private String[] stringCache;
3940 private Map<String, DateFormat> dateFormatCache;
4041 private Map<String, NumberFormat> numberFormatCache;
4142 private Map<ParameterTypeKey, Type> parameterTypeCache;
42-
43+
4344 public LocalCache(String bundle, Locale locale, TimeZone timeZone) {
4445 this.resources = ResourceBundle.getBundle(bundle, locale);
4546 this.locale = locale;
4647 this.timeZone = timeZone;
4748 }
48-
49+
4950 public StringBuilder getCachedBuffer() {
5051 if (builderCache == null) {
5152 builderCache = new StringBuilder();
@@ -54,18 +55,18 @@
5455 }
5556 return builderCache;
5657 }
57-
58+
5859 public String getString(CharSequence cs) {
5960 if (cs.length() == 0) return "";
60-
61- if (cs.length() < 32) {
61+
62+ if (cs.length() < 32 && stringCacheCount++ > 16) {
6263 int index = getCacheIndex(cs);
6364 if (index < 0) {
6465 return cs.toString();
6566 }
66-
67+
6768 if (stringCache == null) stringCache = new String[CACHE_SIZE];
68-
69+
6970 String str = stringCache[index];
7071 if (str == null || str.length() != cs.length()) {
7172 str = cs.toString();
@@ -72,7 +73,7 @@
7273 stringCache[index] = str;
7374 return str;
7475 }
75-
76+
7677 for (int i = 0; i < cs.length(); i++) {
7778 if (str.charAt(i) != cs.charAt(i)) {
7879 str = cs.toString();
@@ -82,10 +83,10 @@
8283 }
8384 return str;
8485 }
85-
86+
8687 return cs.toString();
8788 }
88-
89+
8990 private int getCacheIndex(CharSequence cs) {
9091 int h = 0;
9192 int max = Math.min(16, cs.length());
@@ -94,7 +95,7 @@
9495 }
9596 return h & (CACHE_SIZE-1);
9697 }
97-
98+
9899 public NumberFormat getNumberFormat(String format) {
99100 NumberFormat nformat = null;
100101 if (numberFormatCache == null) {
@@ -108,7 +109,7 @@
108109 }
109110 return nformat;
110111 }
111-
112+
112113 public DateFormat getDateFormat(String format) {
113114 DateFormat dformat = null;
114115 if (dateFormatCache == null) {
@@ -123,7 +124,7 @@
123124 }
124125 return dformat;
125126 }
126-
127+
127128 public Type getParameterType(Type t, Class<?> cls, int pos) {
128129 ParameterTypeKey key = new ParameterTypeKey(t, cls, pos);
129130 Type result = null;
@@ -138,11 +139,11 @@
138139 }
139140 return result;
140141 }
141-
142+
142143 public String getMessage(String id) {
143144 return getMessage(id, (Object[])null);
144145 }
145-
146+
146147 public String getMessage(String id, Object... args) {
147148 if (args != null && args.length > 0) {
148149 return MessageFormat.format(resources.getString(id), args);
@@ -150,12 +151,12 @@
150151 return resources.getString(id);
151152 }
152153 }
153-
154+
154155 private static class ParameterTypeKey {
155156 private Type t;
156157 private Class<?> cls;
157158 private int pos;
158-
159+
159160 public ParameterTypeKey(Type t, Class<?> cls, int pos) {
160161 this.t = t;
161162 this.cls = cls;
旧リポジトリブラウザで表示