diff options
author | Assaf <asafyi@gmail.com> | 2018-06-20 14:06:04 +0300 |
---|---|---|
committer | Ben Gruver <bgruv@google.com> | 2018-08-22 12:43:34 -0700 |
commit | 7542a6b531bc907968f513eb1969b91c1c9ebe26 (patch) | |
tree | c4601efe8fd1cf76b2d64d0bb3f9b10b139dd9a6 | |
parent | 86963ccb43b7be83d5d333854e14af51e8e84ba7 (diff) | |
download | smali-7542a6b531bc907968f513eb1969b91c1c9ebe26.tar.gz |
Simplify getLabels() by using two separate methods.
-rw-r--r-- | dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java index 5a707e92..762aadae 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/builder/MethodLocation.java @@ -75,22 +75,42 @@ public class MethodLocation { } @Nonnull - private List<Label> getLabels(boolean mutable) { + private List<Label> getMutableLabels() { + if (labels == null) { + labels = new ArrayList<>(1); + } + return labels; + } + + @Nonnull + private List<Label> getImmutableLabels() { if (labels == null) { - if (mutable) { - labels = new ArrayList<Label>(1); - return labels; - } return ImmutableList.of(); } return labels; } @Nonnull + private List<BuilderDebugItem> getMutableDebugItems() { + if (debugItems == null) { + debugItems = new ArrayList<>(1); + } + return debugItems; + } + + @Nonnull + private List<BuilderDebugItem> getImmutableDebugItems() { + if (debugItems == null) { + return ImmutableList.of(); + } + return debugItems; + } + + @Nonnull private List<BuilderDebugItem> getDebugItems(boolean mutable) { if (debugItems == null) { if (mutable) { - debugItems = new ArrayList<BuilderDebugItem>(1); + debugItems = new ArrayList<>(1); return debugItems; } return ImmutableList.of(); @@ -100,8 +120,8 @@ public class MethodLocation { void mergeInto(@Nonnull MethodLocation other) { if (this.labels != null || other.labels != null) { - List<Label> otherLabels = other.getLabels(true); - for (Label label: this.getLabels(false)) { + List<Label> otherLabels = other.getMutableLabels(); + for (Label label: this.getImmutableLabels()) { label.location = other; otherLabels.add(label); } @@ -111,11 +131,11 @@ public class MethodLocation { if (this.debugItems != null || other.labels != null) { // We need to keep the debug items in the same order. We add the other debug items to this list, then reassign // the list. - List<BuilderDebugItem> debugItems = getDebugItems(true); + List<BuilderDebugItem> debugItems = getMutableDebugItems(); for (BuilderDebugItem debugItem: debugItems) { debugItem.location = other; } - debugItems.addAll(other.getDebugItems(false)); + debugItems.addAll(other.getImmutableDebugItems()); other.debugItems = debugItems; this.debugItems = null; } @@ -126,7 +146,7 @@ public class MethodLocation { return new AbstractSet<Label>() { @Nonnull @Override public Iterator<Label> iterator() { - final Iterator<Label> it = getLabels(false).iterator(); + final Iterator<Label> it = getImmutableLabels().iterator(); return new Iterator<Label>() { private @Nullable Label currentLabel = null; @@ -150,7 +170,7 @@ public class MethodLocation { } @Override public int size() { - return getLabels(false).size(); + return getImmutableLabels().size(); } @Override public boolean add(@Nonnull Label label) { @@ -159,7 +179,7 @@ public class MethodLocation { "it from its current location first."); } label.location = MethodLocation.this; - getLabels(true).add(label); + getMutableLabels().add(label); return true; } }; @@ -168,7 +188,7 @@ public class MethodLocation { @Nonnull public Label addNewLabel() { Label label = new Label(this); - getLabels(true).add(label); + getMutableLabels().add(label); return label; } @@ -177,7 +197,7 @@ public class MethodLocation { return new AbstractSet<BuilderDebugItem>() { @Nonnull @Override public Iterator<BuilderDebugItem> iterator() { - final Iterator<BuilderDebugItem> it = getDebugItems(false).iterator(); + final Iterator<BuilderDebugItem> it = getImmutableDebugItems().iterator(); return new Iterator<BuilderDebugItem>() { private @Nullable BuilderDebugItem currentDebugItem = null; @@ -201,7 +221,7 @@ public class MethodLocation { } @Override public int size() { - return getDebugItems(false).size(); + return getImmutableDebugItems().size(); } @Override public boolean add(@Nonnull BuilderDebugItem debugItem) { @@ -210,7 +230,7 @@ public class MethodLocation { "method. You must remove it from its current location first."); } debugItem.location = MethodLocation.this; - getDebugItems(true).add(debugItem); + getMutableDebugItems().add(debugItem); return true; } }; |