1 11 package org.eclipse.jdt.internal.compiler; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; 16 17 public class ClassFilePool { 18 public static final int POOL_SIZE = 7; 19 ClassFile[] classFiles; 20 21 private ClassFilePool() { 22 this.classFiles = new ClassFile[POOL_SIZE]; 24 } 25 26 public static ClassFilePool newInstance() { 27 return new ClassFilePool(); 28 } 29 30 public void release(ClassFile classFile) { 31 for (int i = 0; i < POOL_SIZE; i++) { 32 ClassFile currentClassFile = this.classFiles[i]; 33 if (currentClassFile == classFile) { 34 classFile.isShared = false; 35 return; 36 } 37 } 38 } 39 40 public ClassFile acquire(SourceTypeBinding typeBinding) { 41 for (int i = 0; i < POOL_SIZE; i++) { 42 ClassFile classFile = this.classFiles[i]; 43 if (classFile == null) { 44 ClassFile newClassFile = new ClassFile(typeBinding); 45 this.classFiles[i] = newClassFile; 46 newClassFile.isShared = true; 47 return newClassFile; 48 } 49 if (classFile.isShared) { 50 continue; 51 } 52 classFile.reset(typeBinding); 53 classFile.isShared = true; 54 return classFile; 55 } 56 return new ClassFile(typeBinding); 57 } 58 public void reset() { 59 Arrays.fill(this.classFiles, null); 60 } 61 } 69 70 | Popular Tags |