Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore pre-1.0.0 behavior for codepoint funs and ObjectEqualityComparator #199

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal const val MIN_LOW_SURROGATE: Int = 0xDC00
internal const val HIGH_SURROGATE_ENCODE_OFFSET: Int =
(MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT_ ushr 10))

internal inline fun isBmpCodePoint(codePoint: Int): Boolean =
internal fun isBmpCodePoint(codePoint: Int): Boolean =
codePoint ushr 16 == 0

internal inline fun highSurrogate(codePoint: Int): Char =
internal fun highSurrogate(codePoint: Int): Char =
((codePoint ushr 10) + HIGH_SURROGATE_ENCODE_OFFSET).toChar()

internal inline fun lowSurrogate(codePoint: Int): Char =
internal fun lowSurrogate(codePoint: Int): Char =
((codePoint and 0x3FF) + MIN_LOW_SURROGATE).toChar()

internal inline fun isValidCodePoint(codePoint: Int): Boolean =
internal fun isValidCodePoint(codePoint: Int): Boolean =
codePoint in 0..MAX_CODE_POINT_
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.

package org.antlr.v4.kotlinruntime.atn

import org.antlr.v4.kotlinruntime.misc.MurmurHash
Expand Down Expand Up @@ -89,7 +88,7 @@ public class LexerATNConfig : ATNConfig {
return false
}

if (!ObjectEqualityComparator.equals(lexerActionExecutor, other.lexerActionExecutor)) {
if (!ObjectEqualityComparator.INSTANCE.equals(lexerActionExecutor, other.lexerActionExecutor)) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.

package org.antlr.v4.kotlinruntime.atn

import org.antlr.v4.kotlinruntime.misc.ObjectEqualityComparator
Expand All @@ -9,7 +8,7 @@ import org.antlr.v4.kotlinruntime.misc.ObjectEqualityComparator
* @author Sam Harwell
*/
public class OrderedATNConfigSet : ATNConfigSet() {
public class LexerConfigHashSet : AbstractConfigHashSet(ObjectEqualityComparator)
public class LexerConfigHashSet : AbstractConfigHashSet(ObjectEqualityComparator.INSTANCE)

init {
configLookup = LexerConfigHashSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.math.floor
*/
@Suppress("MemberVisibilityCanBePrivate")
public open class Array2DHashSet<T>(
protected val comparator: AbstractEqualityComparator<T> = ObjectEqualityComparator,
protected val comparator: AbstractEqualityComparator<T> = ObjectEqualityComparator.INSTANCE,
protected val initialCapacity: Int = INITIAL_CAPACITY,
protected val initialBucketCapacity: Int = INITIAL_BUCKET_CAPACITY,
) : MutableSet<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.math.floor
*/
@Suppress("MemberVisibilityCanBePrivate", "CanBeParameter")
public open class FlexibleHashMap<K, V>(
protected val comparator: AbstractEqualityComparator<K> = ObjectEqualityComparator,
protected val comparator: AbstractEqualityComparator<K> = ObjectEqualityComparator.INSTANCE,
public val initialCapacity: Int = INITIAL_CAPACITY,
public val initialBucketCapacity: Int = INITIAL_BUCKET_CAPACITY,
) : MutableMap<K, V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package org.antlr.v4.kotlinruntime.misc

import kotlin.jvm.JvmField

/**
* This default implementation of [EqualityComparator] uses object equality
* for comparisons by calling [Any.hashCode] and [Any.equals].
*
* @author Sam Harwell
*/
public object ObjectEqualityComparator : AbstractEqualityComparator<Any?>() {
override fun hashCode(obj: Any?): Int =
public class ObjectEqualityComparator<in T> : AbstractEqualityComparator<T>() {
public companion object {
@JvmField
public val INSTANCE: ObjectEqualityComparator<Any?> = ObjectEqualityComparator()
}

override fun hashCode(obj: T): Int =
obj?.hashCode() ?: 0

/**
Expand All @@ -21,6 +28,6 @@ public object ObjectEqualityComparator : AbstractEqualityComparator<Any?>() {
*
* Otherwise, this method returns the result of `a == b`.
*/
override fun equals(a: Any?, b: Any?): Boolean =
override fun equals(a: T?, b: T?): Boolean =
(a == null && b == null) || a == b
}
Loading