View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.kryo;
15  
16  import static ch.qos.logback.core.kryo.KryoCoreConstants.MAX_SERIALIZER_ID;
17  
18  /**
19   * Interns serializer ids in {@code 1..MAX_SERIALIZER_ID} so map lookups do not
20   * allocate a new {@link Integer} per call.
21   */
22  final class BoxedIds {
23  
24      private static final Integer[] TABLE = new Integer[MAX_SERIALIZER_ID + 1];
25  
26      private BoxedIds() {
27      }
28  
29      static Integer of(int id) {
30          if (id > 0 && id <= MAX_SERIALIZER_ID) {
31              Integer boxed = TABLE[id];
32              if (boxed == null) {
33                  boxed = Integer.valueOf(id);
34                  TABLE[id] = boxed;
35              }
36              return boxed;
37          }
38          return Integer.valueOf(id);
39      }
40  }