Skip to content

Commit ae2cb61

Browse files
committed
define hashcode as lazy val
1 parent 55a6154 commit ae2cb61

File tree

38 files changed

+53
-43
lines changed

38 files changed

+53
-43
lines changed

benchmarks/src/main/scala/org/typelevel/otel4s/benchmarks/AttributesBenchmark.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AttributesBenchmark {
3535

3636
@Benchmark
3737
def java_computeHashCode(): Unit = {
38-
for (a <- jAttributes) { a.hashCode() }
38+
for (a <- jAttributes) { a.hashCode }
3939
}
4040

4141
@Benchmark
@@ -69,7 +69,7 @@ class AttributesBenchmark {
6969
@Benchmark
7070
def otel4s_computeHashCode(): Unit = {
7171
for (a <- attributes) {
72-
a.hashCode()
72+
a.hashCode
7373
}
7474
}
7575

core/common/src/main/scala/org/typelevel/otel4s/AnyValue.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ object AnyValue {
133133
case LongValueImpl(value) => Hash[Long].hash(value)
134134
case DoubleValueImpl(value) => Hash[Double].hash(value)
135135
case ByteArrayValueImpl(value) => java.util.Arrays.hashCode(value)
136-
case ListValueImpl(values) => values.map(hash).hashCode()
137-
case MapValueImpl(values) => values.map { case (k, v) => (k, hash(v)) }.hashCode()
136+
case ListValueImpl(values) => values.map(hash).hashCode
137+
case MapValueImpl(values) => values.map { case (k, v) => (k, hash(v)) }.hashCode
138138
case _: EmptyValue => System.identityHashCode(EmptyValueImpl)
139139
}
140140

core/common/src/main/scala/org/typelevel/otel4s/Attribute.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.typelevel.otel4s
1919
import cats.Hash
2020
import cats.Show
2121
import cats.syntax.show._
22+
import org.typelevel.scalaccompat.annotation.threadUnsafe3
2223

2324
/** Represents the key-value attribute.
2425
*
@@ -38,7 +39,8 @@ sealed trait Attribute[A] {
3839
*/
3940
def value: A
4041

41-
override final def hashCode(): Int =
42+
@threadUnsafe3
43+
override final lazy val hashCode: Int =
4244
Hash[Attribute[_]].hash(this)
4345

4446
override final def equals(obj: Any): Boolean =

core/common/src/main/scala/org/typelevel/otel4s/AttributeKey.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.typelevel.otel4s
1919
import cats.Hash
2020
import cats.Show
2121
import cats.syntax.show._
22+
import org.typelevel.scalaccompat.annotation.threadUnsafe3
2223

2324
/** The type of value that can be set with an implementation of this key is denoted by the type parameter.
2425
*
@@ -97,7 +98,8 @@ object AttributeKey {
9798
override final def toString: String =
9899
Show[AttributeKey[A]].show(this)
99100

100-
override final def hashCode(): Int =
101+
@threadUnsafe3
102+
override final lazy val hashCode: Int =
101103
Hash[AttributeKey[A]].hash(this)
102104

103105
override final def equals(obj: Any): Boolean =

core/common/src/main/scala/org/typelevel/otel4s/Attributes.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import cats.Monoid
2121
import cats.Show
2222
import cats.syntax.show._
2323
import org.typelevel.otel4s.AttributeKey.KeySelect
24+
import org.typelevel.scalaccompat.annotation.threadUnsafe3
2425

2526
import scala.collection.IterableOps
2627
import scala.collection.SpecificIterableFactory
@@ -105,7 +106,8 @@ sealed trait Attributes
105106
attributesFactory.newBuilder
106107
override protected[this] def className: String = "Attributes"
107108

108-
override def hashCode(): Int =
109+
@threadUnsafe3
110+
override lazy val hashCode: Int =
109111
Hash[Attributes].hash(this)
110112

111113
override def equals(obj: Any): Boolean =

core/common/src/main/scala/org/typelevel/otel4s/baggage/Baggage.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ sealed trait Baggage {
9191
/** Returns a map representation of this baggage. */
9292
def asMap: Map[String, Baggage.Entry]
9393

94-
override final def hashCode(): Int =
94+
override final lazy val hashCode: Int =
9595
Hash[Baggage].hash(this)
9696

9797
override final def equals(obj: Any): Boolean =
@@ -114,7 +114,7 @@ object Baggage {
114114
sealed trait Metadata {
115115
def value: String
116116

117-
override final def hashCode(): Int =
117+
override final lazy val hashCode: Int =
118118
Hash[Metadata].hash(this)
119119

120120
override final def equals(obj: Any): Boolean =
@@ -149,7 +149,7 @@ object Baggage {
149149
*/
150150
def metadata: Option[Metadata]
151151

152-
override final def hashCode(): Int =
152+
override final lazy val hashCode: Int =
153153
Hash[Entry].hash(this)
154154

155155
override final def equals(obj: Any): Boolean =

core/logs/src/main/scala/org/typelevel/otel4s/logs/Severity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import cats.Show
3333
*/
3434
sealed abstract class Severity(val value: Int, val name: String) {
3535

36-
override final def hashCode(): Int =
36+
override final lazy val hashCode: Int =
3737
Hash[Severity].hash(this)
3838

3939
override final def equals(obj: Any): Boolean =

core/metrics/src/main/scala/org/typelevel/otel4s/metrics/BucketBoundaries.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sealed trait BucketBoundaries {
2626

2727
final def length: Int = boundaries.length
2828

29-
override final def hashCode(): Int =
29+
override final lazy val hashCode: Int =
3030
Hash[BucketBoundaries].hash(this)
3131

3232
override final def equals(obj: Any): Boolean =

core/trace/src/main/scala/org/typelevel/otel4s/trace/SpanContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sealed trait SpanContext {
6868
*/
6969
def isRemote: Boolean
7070

71-
override final def hashCode(): Int =
71+
override final lazy val hashCode: Int =
7272
Hash[SpanContext].hash(this)
7373

7474
override final def equals(obj: Any): Boolean =

core/trace/src/main/scala/org/typelevel/otel4s/trace/TraceFlags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sealed trait TraceFlags {
3838
*/
3939
def isSampled: Boolean
4040

41-
override final def hashCode(): Int =
41+
override final lazy val hashCode: Int =
4242
Hash[TraceFlags].hash(this)
4343

4444
override final def equals(obj: Any): Boolean =

0 commit comments

Comments
 (0)