mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -774,23 +774,25 @@ public class GeneratedParserUtilBase {
|
||||
MyList<Variant> unexpected = new MyList<Variant>(INITIAL_VARIANTS_SIZE / 10);
|
||||
|
||||
final LimitedPool<Variant> VARIANTS = new LimitedPool<Variant>(VARIANTS_POOL_SIZE, new LimitedPool.ObjectFactory<Variant>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Variant create() {
|
||||
return new Variant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(final Variant o) {
|
||||
public void cleanup(@NotNull final Variant o) {
|
||||
}
|
||||
});
|
||||
final LimitedPool<Frame> FRAMES = new LimitedPool<Frame>(FRAMES_POOL_SIZE, new LimitedPool.ObjectFactory<Frame>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Frame create() {
|
||||
return new Frame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(final Frame o) {
|
||||
public void cleanup(@NotNull final Frame o) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.util.containers;
|
||||
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/*
|
||||
@@ -25,19 +26,21 @@ public class LimitedPool<T> {
|
||||
private final int capacity;
|
||||
private final ObjectFactory<T> factory;
|
||||
private Object[] storage;
|
||||
private int index = 0;
|
||||
private int index;
|
||||
|
||||
public LimitedPool(final int capacity, ObjectFactory<T> factory) {
|
||||
public LimitedPool(final int capacity, @NotNull ObjectFactory<T> factory) {
|
||||
this.capacity = capacity;
|
||||
this.factory = factory;
|
||||
storage = new Object[10];
|
||||
}
|
||||
|
||||
public interface ObjectFactory<T> {
|
||||
@NotNull
|
||||
T create();
|
||||
void cleanup(T t);
|
||||
void cleanup(@NotNull T t);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T alloc() {
|
||||
if (index == 0) return factory.create();
|
||||
int i = --index;
|
||||
@@ -59,9 +62,7 @@ public class LimitedPool<T> {
|
||||
private void ensureCapacity() {
|
||||
if (storage.length <= index) {
|
||||
int newCapacity = Math.min(capacity, storage.length * 3 / 2);
|
||||
Object[] newStorage = new Object[newCapacity];
|
||||
System.arraycopy(storage, 0, newStorage, 0, storage.length);
|
||||
storage = newStorage;
|
||||
storage = ArrayUtil.realloc(storage, newCapacity, ArrayUtil.OBJECT_ARRAY_FACTORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.intellij.util.io;
|
||||
|
||||
import com.intellij.util.containers.LimitedPool;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -29,13 +30,14 @@ public class Page {
|
||||
public static final int PAGE_SIZE = 4 * 1024;
|
||||
|
||||
private static final LimitedPool<ByteBuffer> ourBufferPool = new LimitedPool<ByteBuffer>(10, new LimitedPool.ObjectFactory<ByteBuffer>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public ByteBuffer create() {
|
||||
return ByteBuffer.allocate(PAGE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(final ByteBuffer byteBuffer) {
|
||||
public void cleanup(@NotNull final ByteBuffer byteBuffer) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user