use more high-level methods to copy arrays instead of low-level cryptic System.arraycopy()

GitOrigin-RevId: 16b9869eae4200f4ff24c4535d7f33d8e6847b4c
master
Alexey Kudravtsev 4 years ago committed by intellij-monorepo-bot
parent 50691f39fb
commit 7f65f48b3f
  1. 3
      src/org/jetbrains/java/decompiler/struct/gen/MethodDescriptor.java
  2. 8
      src/org/jetbrains/java/decompiler/util/FastFixedSetFactory.java
  3. 26
      src/org/jetbrains/java/decompiler/util/FastSparseSetFactory.java
  4. 5
      src/org/jetbrains/java/decompiler/util/SFormsFastMapDirect.java

@ -68,8 +68,7 @@ public final class MethodDescriptor {
VarType[] newParams;
if (params.length > 0) {
newParams = new VarType[params.length];
System.arraycopy(params, 0, newParams, 0, params.length);
newParams = params.clone();
for (int i = 0; i < params.length; i++) {
VarType substitute = buildNewType(params[i], builder);
if (substitute != null) {

@ -1,10 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.util;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
public class FastFixedSetFactory<E> {
@ -66,8 +63,7 @@ public class FastFixedSetFactory<E> {
FastFixedSet<E> copy = new FastFixedSet<>(factory);
int arrlength = data.length;
int[] cpdata = new int[arrlength];
System.arraycopy(data, 0, cpdata, 0, arrlength);
int[] cpdata = Arrays.copyOf(data, arrlength);
copy.setData(cpdata);
return copy;

@ -1,10 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.util;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
public class FastSparseSetFactory<E> {
@ -97,15 +94,7 @@ public class FastSparseSetFactory<E> {
}
public FastSparseSet<E> getCopy() {
int arrlength = data.length;
int[] cpdata = new int[arrlength];
int[] cpnext = new int[arrlength];
System.arraycopy(data, 0, cpdata, 0, arrlength);
System.arraycopy(next, 0, cpnext, 0, arrlength);
return new FastSparseSet<>(factory, cpdata, cpnext);
return new FastSparseSet<>(factory, data.clone(), next.clone());
}
private int[] ensureCapacity(int index) {
@ -119,15 +108,10 @@ public class FastSparseSetFactory<E> {
newlength *= 2;
}
int[] newdata = new int[newlength];
System.arraycopy(data, 0, newdata, 0, data.length);
data = newdata;
data = Arrays.copyOf(data, newlength);
next = Arrays.copyOf(next, newlength);
int[] newnext = new int[newlength];
System.arraycopy(next, 0, newnext, 0, next.length);
next = newnext;
return newdata;
return data;
}
public void add(E element) {

@ -5,6 +5,7 @@ import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
import org.jetbrains.java.decompiler.util.FastSparseSetFactory.FastSparseSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
@ -66,9 +67,7 @@ public class SFormsFastMapDirect {
int[] arrnext = next[i];
@SuppressWarnings("unchecked") FastSparseSet<Integer>[] arrnew = new FastSparseSet[length];
int[] arrnextnew = new int[length];
System.arraycopy(arrnext, 0, arrnextnew, 0, length);
int[] arrnextnew = Arrays.copyOf(arrnext, length);
mapelements[i] = arrnew;
mapnext[i] = arrnextnew;

Loading…
Cancel
Save