1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/* 20888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Copyright (C) 2009 The Guava Authors 3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License. 6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at 7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and 14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License. 15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 170888a09821a98ac0680fad765217302858e70fa4Paul Duffinpackage com.google.common.escape; 181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 190888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.common.annotations.GwtCompatible; 20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/** 221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Methods factored out so that they can be emulated differently in GWT. 23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 240888a09821a98ac0680fad765217302858e70fa4Paul Duffin * @author Jesse Wilson 25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 260888a09821a98ac0680fad765217302858e70fa4Paul Duffin@GwtCompatible(emulated = true) 271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertfinal class Platform { 280888a09821a98ac0680fad765217302858e70fa4Paul Duffin private Platform() {} 290888a09821a98ac0680fad765217302858e70fa4Paul Duffin 300888a09821a98ac0680fad765217302858e70fa4Paul Duffin /** Returns a thread-local 1024-char array. */ 310888a09821a98ac0680fad765217302858e70fa4Paul Duffin static char[] charBufferFromThreadLocal() { 320888a09821a98ac0680fad765217302858e70fa4Paul Duffin return DEST_TL.get(); 33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 350888a09821a98ac0680fad765217302858e70fa4Paul Duffin /** 360888a09821a98ac0680fad765217302858e70fa4Paul Duffin * A thread-local destination buffer to keep us from creating new buffers. 370888a09821a98ac0680fad765217302858e70fa4Paul Duffin * The starting size is 1024 characters. If we grow past this we don't 380888a09821a98ac0680fad765217302858e70fa4Paul Duffin * put it back in the threadlocal, we just keep going and grow as needed. 390888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 400888a09821a98ac0680fad765217302858e70fa4Paul Duffin private static final ThreadLocal<char[]> DEST_TL = new ThreadLocal<char[]>() { 410888a09821a98ac0680fad765217302858e70fa4Paul Duffin @Override 420888a09821a98ac0680fad765217302858e70fa4Paul Duffin protected char[] initialValue() { 430888a09821a98ac0680fad765217302858e70fa4Paul Duffin return new char[1024]; 440888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 450888a09821a98ac0680fad765217302858e70fa4Paul Duffin }; 46090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson} 47