1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
489
490 public void put(final int index, final long value) {
491 final int firstIndex = index >> shift;
492 long[] firstLayerRow = cache[firstIndex];
493 if (firstLayerRow == null) {
494 cache[firstIndex] = firstLayerRow = new long[secondLayerLength];
495 }
496 firstLayerRow[index - (firstIndex * (1 << shift))] = value;
497 }
498 }
499 }
500
501 private static class GlyphAdvanceCache {
502 private static final int FIRST_LAYER_SIZE = 256;
503 private static final int SECOND_LAYER_SIZE = 16384; // 16384 = 128x128
504
505 private final float[] firstLayerCache = new float[FIRST_LAYER_SIZE];
506 private SparseBitShiftingTwoLayerArray secondLayerCache;
507 private HashMap<Integer, Float> generalCache;
508
509 // Empty non private constructor was added because access to this
510 // class shouldn't be emulated by a synthetic accessor method.
511 GlyphAdvanceCache() {
512 super();
513 }
514
515 public synchronized float get(final int index) {
516 if (index < 0) {
517 if (-index < SECOND_LAYER_SIZE) {
518 // catch common unicodes
519 if (secondLayerCache == null) return 0;
520 return secondLayerCache.get(-index);
521 }
522 } else {
523 if (index < FIRST_LAYER_SIZE) {
524 // catch common glyphcodes
525 return firstLayerCache[index];
526 }
527 }
528
529 if (generalCache == null) return 0;
530 final Float value = generalCache.get(Integer.valueOf(index));
531 if (value == null) return 0;
532 return value.floatValue();
533 }
534
|
1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
489
490 public void put(final int index, final long value) {
491 final int firstIndex = index >> shift;
492 long[] firstLayerRow = cache[firstIndex];
493 if (firstLayerRow == null) {
494 cache[firstIndex] = firstLayerRow = new long[secondLayerLength];
495 }
496 firstLayerRow[index - (firstIndex * (1 << shift))] = value;
497 }
498 }
499 }
500
501 private static class GlyphAdvanceCache {
502 private static final int FIRST_LAYER_SIZE = 256;
503 private static final int SECOND_LAYER_SIZE = 16384; // 16384 = 128x128
504
505 private final float[] firstLayerCache = new float[FIRST_LAYER_SIZE];
506 private SparseBitShiftingTwoLayerArray secondLayerCache;
507 private HashMap<Integer, Float> generalCache;
508
509 public synchronized float get(final int index) {
510 if (index < 0) {
511 if (-index < SECOND_LAYER_SIZE) {
512 // catch common unicodes
513 if (secondLayerCache == null) return 0;
514 return secondLayerCache.get(-index);
515 }
516 } else {
517 if (index < FIRST_LAYER_SIZE) {
518 // catch common glyphcodes
519 return firstLayerCache[index];
520 }
521 }
522
523 if (generalCache == null) return 0;
524 final Float value = generalCache.get(Integer.valueOf(index));
525 if (value == null) return 0;
526 return value.floatValue();
527 }
528
|