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; VarType[] newParams;
if (params.length > 0) { if (params.length > 0) {
newParams = new VarType[params.length]; newParams = params.clone();
System.arraycopy(params, 0, newParams, 0, params.length);
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
VarType substitute = buildNewType(params[i], builder); VarType substitute = buildNewType(params[i], builder);
if (substitute != null) { 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. // 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; package org.jetbrains.java.decompiler.util;
import java.util.Collection; import java.util.*;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class FastFixedSetFactory<E> { public class FastFixedSetFactory<E> {
@ -66,8 +63,7 @@ public class FastFixedSetFactory<E> {
FastFixedSet<E> copy = new FastFixedSet<>(factory); FastFixedSet<E> copy = new FastFixedSet<>(factory);
int arrlength = data.length; int arrlength = data.length;
int[] cpdata = new int[arrlength]; int[] cpdata = Arrays.copyOf(data, arrlength);
System.arraycopy(data, 0, cpdata, 0, arrlength);
copy.setData(cpdata); copy.setData(cpdata);
return copy; 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. // 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; package org.jetbrains.java.decompiler.util;
import java.util.Collection; import java.util.*;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class FastSparseSetFactory<E> { public class FastSparseSetFactory<E> {
@ -97,15 +94,7 @@ public class FastSparseSetFactory<E> {
} }
public FastSparseSet<E> getCopy() { public FastSparseSet<E> getCopy() {
return new FastSparseSet<>(factory, data.clone(), next.clone());
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);
} }
private int[] ensureCapacity(int index) { private int[] ensureCapacity(int index) {
@ -119,15 +108,10 @@ public class FastSparseSetFactory<E> {
newlength *= 2; newlength *= 2;
} }
int[] newdata = new int[newlength]; data = Arrays.copyOf(data, newlength);
System.arraycopy(data, 0, newdata, 0, data.length); next = Arrays.copyOf(next, newlength);
data = newdata;
int[] newnext = new int[newlength]; return data;
System.arraycopy(next, 0, newnext, 0, next.length);
next = newnext;
return newdata;
} }
public void add(E element) { 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 org.jetbrains.java.decompiler.util.FastSparseSetFactory.FastSparseSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
@ -66,9 +67,7 @@ public class SFormsFastMapDirect {
int[] arrnext = next[i]; int[] arrnext = next[i];
@SuppressWarnings("unchecked") FastSparseSet<Integer>[] arrnew = new FastSparseSet[length]; @SuppressWarnings("unchecked") FastSparseSet<Integer>[] arrnew = new FastSparseSet[length];
int[] arrnextnew = new int[length]; int[] arrnextnew = Arrays.copyOf(arrnext, length);
System.arraycopy(arrnext, 0, arrnextnew, 0, length);
mapelements[i] = arrnew; mapelements[i] = arrnew;
mapnext[i] = arrnextnew; mapnext[i] = arrnextnew;

Loading…
Cancel
Save