All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.IntCache Maven / Gradle / Ivy

package net.minecraft.server;

import com.google.common.collect.Lists;

import java.util.List;

public class IntCache {

  private static int a = 256;
  private static final List b = Lists.newArrayList();
  private static final List c = Lists.newArrayList();
  private static final List d = Lists.newArrayList();
  private static final List e = Lists.newArrayList();

  public static synchronized int[] a(int i) {
    int[] aint;

    if (i <= 256) {
      if (IntCache.b.isEmpty()) {
        aint = new int[256];
        if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.c.add(aint);
        return aint;
      } else {
        aint = IntCache.b.remove(IntCache.b.size() - 1);
        if (c.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.c.add(aint);
        return aint;
      }
    } else if (i > IntCache.a) {
      IntCache.a = i;
      IntCache.d.clear();
      IntCache.e.clear();
      aint = new int[IntCache.a];
      if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
      return aint;
    } else if (IntCache.d.isEmpty()) {
      aint = new int[IntCache.a];
      if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
      return aint;
    } else {
      aint = IntCache.d.remove(IntCache.d.size() - 1);
      if (e.size() < org.spigotmc.SpigotConfig.intCacheLimit) IntCache.e.add(aint);
      return aint;
    }
  }

  public static synchronized void a() {
    if (!IntCache.d.isEmpty()) {
      IntCache.d.remove(IntCache.d.size() - 1);
    }

    if (!IntCache.b.isEmpty()) {
      IntCache.b.remove(IntCache.b.size() - 1);
    }

    IntCache.d.addAll(IntCache.e);
    IntCache.b.addAll(IntCache.c);
    IntCache.e.clear();
    IntCache.c.clear();
  }

  public static synchronized String b() {
    return "cache: " + IntCache.d.size() + ", tcache: " + IntCache.b.size() + ", allocated: " + IntCache.e.size() + ", tallocated: " + IntCache.c.size();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy