Skip to content

Commit

Permalink
Compare all primitive value type wrappers by value
Browse files Browse the repository at this point in the history
  • Loading branch information
szegedi authored and rbri committed Apr 9, 2023
1 parent 9f6f3bb commit add208c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/org/mozilla/javascript/EqualObjectGraphs.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.mozilla.javascript;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -37,6 +39,19 @@
final class EqualObjectGraphs {
private static final ThreadLocal<EqualObjectGraphs> instance = new ThreadLocal<>();

private static final Set<Class<?>> valueClasses =
Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList(
Boolean.class,
Byte.class,
Character.class,
Double.class,
Float.class,
Integer.class,
Long.class,
Short.class)));

// Object pairs already known to be equal. Used to short-circuit repeated traversals of objects
// reachable through
// different paths as well as to detect structural inequality.
Expand Down Expand Up @@ -76,7 +91,7 @@ boolean equalGraphs(Object o1, Object o2) {
return o1.toString().equals(o2.toString());
}
return false;
} else if (o1 instanceof Boolean || o1 instanceof Double) {
} else if (valueClasses.contains(o1.getClass())) {
return o1.equals(o2);
}

Expand Down

0 comments on commit add208c

Please sign in to comment.