-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize
Function0
allocations (#2366)
- Loading branch information
1 parent
75af320
commit c0bc120
Showing
11 changed files
with
97 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package caliban | ||
|
||
import scala.annotation.StaticAnnotation | ||
|
||
/** | ||
* Stubs for annotations that exist in Scala 3 but not in Scala 2 | ||
*/ | ||
private[caliban] object Scala3Annotations { | ||
final class static extends StaticAnnotation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package caliban | ||
|
||
import scala.collection.mutable | ||
|
||
private[caliban] object syntax { | ||
val NullFn: () => AnyRef = () => null | ||
|
||
implicit class EnrichedImmutableMapOps[K, V <: AnyRef](private val self: Map[K, V]) extends AnyVal { | ||
def getOrElseNull(key: K): V = self.getOrElse(key, NullFn()).asInstanceOf[V] | ||
} | ||
|
||
implicit class EnrichedHashMapOps[K, V <: AnyRef](private val self: mutable.HashMap[K, V]) extends AnyVal { | ||
def getOrElseNull(key: K): V = self.getOrElse(key, NullFn()).asInstanceOf[V] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package caliban | ||
|
||
import scala.annotation | ||
|
||
/** | ||
* Proxies for annotations that exist in Scala 3 but not in Scala 2 | ||
*/ | ||
private[caliban] object Scala3Annotations { | ||
type static = annotation.static | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package caliban | ||
|
||
import scala.annotation.static | ||
|
||
import scala.collection.mutable | ||
|
||
private[caliban] object syntax { | ||
@static val NullFn: () => AnyRef = () => null | ||
|
||
extension [K, V <: AnyRef](inline map: Map[K, V]) { | ||
transparent inline def getOrElseNull(key: K): V = map.getOrElse(key, NullFn()).asInstanceOf[V] | ||
} | ||
|
||
extension [K, V <: AnyRef](inline map: mutable.HashMap[K, V]) { | ||
transparent inline def getOrElseNull(key: K): V = map.getOrElse(key, NullFn()).asInstanceOf[V] | ||
} | ||
} | ||
|
||
// Required for @static fields | ||
private final class syntax private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters