1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.lib;
13
14 import java.util.zip.Inflater;
15
16
17
18
19 public class InflaterCache {
20 private static final int SZ = 4;
21
22 private static final Inflater[] inflaterCache;
23
24 private static int openInflaterCount;
25
26 static {
27 inflaterCache = new Inflater[SZ];
28 }
29
30
31
32
33
34
35
36
37
38 public static Inflater get() {
39 final Inflater r = getImpl();
40 return r != null ? r : new Inflater(false);
41 }
42
43 private static synchronized Inflater getImpl() {
44 if (openInflaterCount > 0) {
45 final Inflater r = inflaterCache[--openInflaterCount];
46 inflaterCache[openInflaterCount] = null;
47 return r;
48 }
49 return null;
50 }
51
52
53
54
55
56
57
58
59 public static void release(Inflater i) {
60 if (i != null) {
61 i.reset();
62 if (releaseImpl(i))
63 i.end();
64 }
65 }
66
67 private static synchronized boolean releaseImpl(Inflater i) {
68 if (openInflaterCount < SZ) {
69 inflaterCache[openInflaterCount++] = i;
70 return false;
71 }
72 return true;
73 }
74
75 private InflaterCache() {
76 throw new UnsupportedOperationException();
77 }
78 }