Skip to content

Commit

Permalink
Additional simplification of PropListItem
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=163769853
  • Loading branch information
concavelenz authored and dimvar committed Aug 1, 2017
1 parent 82c0429 commit 2cb21a0
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions src/com/google/javascript/rhino/Node.java
Expand Up @@ -388,34 +388,21 @@ private void readObject(java.io.ObjectInputStream in) throws Exception {
}

private abstract static class PropListItem implements Serializable {
private static final long serialVersionUID = 1L;

private final @Nullable PropListItem next;
private final byte propType;
final @Nullable PropListItem next;
final byte propType;

PropListItem(byte propType, @Nullable PropListItem next) {
this.propType = propType;
this.next = next;
}


public final byte getType() {
return propType;
}

public final @Nullable PropListItem getNext() {
return next;
}

public abstract int getIntValue();
public abstract Object getObjectValue();
public abstract PropListItem chain(@Nullable PropListItem next);
}

// A base class for Object storing props
private static class ObjectPropListItem extends PropListItem {
private static final long serialVersionUID = 1L;

private final Object objectValue;

ObjectPropListItem(byte propType, Object objectValue, @Nullable PropListItem next) {
Expand All @@ -440,14 +427,12 @@ public String toString() {

@Override
public PropListItem chain(@Nullable PropListItem next) {
return new ObjectPropListItem(getType(), objectValue, next);
return new ObjectPropListItem(propType, objectValue, next);
}
}

// A base class for int storing props
private static class IntPropListItem extends PropListItem {
private static final long serialVersionUID = 1L;

final int intValue;

IntPropListItem(byte propType, int intValue, @Nullable PropListItem next) {
Expand All @@ -472,7 +457,7 @@ public String toString() {

@Override
public PropListItem chain(@Nullable PropListItem next) {
return new IntPropListItem(getType(), intValue, next);
return new IntPropListItem(propType, intValue, next);
}
}

Expand Down Expand Up @@ -917,8 +902,8 @@ public void replaceFirstOrChildAfter(@Nullable Node prev, Node newChild) {
@Nullable
PropListItem lookupProperty(byte propType) {
PropListItem x = propListHead;
while (x != null && propType != x.getType()) {
x = x.getNext();
while (x != null && propType != x.propType) {
x = x.next;
}
return x;
}
Expand Down Expand Up @@ -956,11 +941,11 @@ public boolean hasProps() {
private PropListItem removeProp(@Nullable PropListItem item, byte propType) {
if (item == null) {
return null;
} else if (item.getType() == propType) {
return item.getNext();
} else if (item.propType == propType) {
return item.next;
} else {
PropListItem result = removeProp(item.getNext(), propType);
if (result != item.getNext()) {
PropListItem result = removeProp(item.next, propType);
if (result != item.next) {
return item.chain(result);
} else {
return item;
Expand Down Expand Up @@ -1061,14 +1046,14 @@ public TypeI getTypeIBeforeCast() {
// Gets all the property types, in sorted order.
private byte[] getSortedPropTypes() {
int count = 0;
for (PropListItem x = propListHead; x != null; x = x.getNext()) {
for (PropListItem x = propListHead; x != null; x = x.next) {
count++;
}

byte[] keys = new byte[count];
for (PropListItem x = propListHead; x != null; x = x.getNext()) {
for (PropListItem x = propListHead; x != null; x = x.next) {
count--;
keys[count] = x.getType();
keys[count] = x.propType;
}

Arrays.sort(keys);
Expand Down

0 comments on commit 2cb21a0

Please sign in to comment.