aglinxinyuan commented on code in PR #9515:
URL: https://github.com/apache/texera/pull/9515#discussion_r4597469086
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/Tuple.scala:
##########
@@ -83,25 +83,33 @@ case class Tuple @JsonCreator() (
this
}
- override def hashCode: Int =
util.Arrays.deepHashCode(getFields.map(_.asInstanceOf[AnyRef]))
+ override def hashCode: Int =
util.Arrays.deepHashCode(getFields.asInstanceOf[Array[AnyRef]])
override def equals(obj: Any): Boolean =
obj match {
- case that: Tuple =>
- this.schema == that.schema &&
- this.getFields.zip(that.getFields).forall {
- case (field1: Array[Byte], field2: Array[Byte]) =>
- field1.sameElements(field2) // for Binary, use sameElements
instead of == to compare
- case (field1, field2) =>
- field1 == field2
- }
+ case that: Tuple if this.schema == that.schema =>
+ val left = this.getFields
+ val right = that.getFields
+ (0 until math.min(left.length, right.length)).forall(i =>
fieldEquals(left(i), right(i)))
case _ => false
}
+ private def fieldEquals(left: Any, right: Any): Boolean =
+ (left, right) match {
+ case (l: Array[Byte], r: Array[Byte]) => util.Arrays.equals(l, r)
+ case _ => left == right
+ }
Review Comment:
Good catch, and confirmed with `javap` here too — done in 73d6f66b1e:
`equals` now walks the fields with your index loop and `fieldEquals` uses plain
type tests, so neither allocates a `Tuple2`, a `Range` or a lambda anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]