1/*
2 * Copyright (C) 2009 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.base;
18
19import java.util.concurrent.TimeUnit;
20
21/**
22 * @author Jesse Wilson
23 */
24class Platform {
25
26  private static final char[] CHAR_BUFFER = new char[1024];
27
28  static char[] charBufferFromThreadLocal() {
29    // ThreadLocal is not available to GWT, so we always reuse the same
30    // instance.  It is always safe to return the same instance because
31    // javascript is single-threaded, and only used by blocks that doesn't
32    // involve async callbacks.
33    return CHAR_BUFFER;
34  }
35
36  static CharMatcher precomputeCharMatcher(CharMatcher matcher) {
37    // CharMatcher.precomputed() produces CharMatchers that are maybe a little
38    // faster (and that's debatable), but definitely more memory-hungry. We're
39    // choosing to turn .precomputed() into a no-op in GWT, because it doesn't
40    // seem to be a worthwhile tradeoff in a browser.
41    return matcher;
42  }
43
44  static long systemNanoTime() {
45    // System.nanoTime() is not available in GWT, so we get milliseconds
46    // and convert to nanos.
47    return TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
48  }
49}
50