diff --git a/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java b/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java index 830b2697aa97..e6950d3287c9 100644 --- a/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java +++ b/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java @@ -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 unexpected = new MyList(INITIAL_VARIANTS_SIZE / 10); final LimitedPool VARIANTS = new LimitedPool(VARIANTS_POOL_SIZE, new LimitedPool.ObjectFactory() { + @NotNull @Override public Variant create() { return new Variant(); } @Override - public void cleanup(final Variant o) { + public void cleanup(@NotNull final Variant o) { } }); final LimitedPool FRAMES = new LimitedPool(FRAMES_POOL_SIZE, new LimitedPool.ObjectFactory() { + @NotNull @Override public Frame create() { return new Frame(); } @Override - public void cleanup(final Frame o) { + public void cleanup(@NotNull final Frame o) { } }); diff --git a/platform/util/src/com/intellij/util/containers/LimitedPool.java b/platform/util/src/com/intellij/util/containers/LimitedPool.java index 61344fa9bdce..8ab72f22eafe 100644 --- a/platform/util/src/com/intellij/util/containers/LimitedPool.java +++ b/platform/util/src/com/intellij/util/containers/LimitedPool.java @@ -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 { private final int capacity; private final ObjectFactory factory; private Object[] storage; - private int index = 0; + private int index; - public LimitedPool(final int capacity, ObjectFactory factory) { + public LimitedPool(final int capacity, @NotNull ObjectFactory factory) { this.capacity = capacity; this.factory = factory; storage = new Object[10]; } public interface ObjectFactory { + @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 { 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); } } } diff --git a/platform/util/src/com/intellij/util/io/Page.java b/platform/util/src/com/intellij/util/io/Page.java index a9885110de30..130445365fd0 100644 --- a/platform/util/src/com/intellij/util/io/Page.java +++ b/platform/util/src/com/intellij/util/io/Page.java @@ -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 ourBufferPool = new LimitedPool(10, new LimitedPool.ObjectFactory() { + @NotNull @Override public ByteBuffer create() { return ByteBuffer.allocate(PAGE_SIZE); } @Override - public void cleanup(final ByteBuffer byteBuffer) { + public void cleanup(@NotNull final ByteBuffer byteBuffer) { } });