-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate Int|Short|Long.reverseBytes to Java Stdlib (#414)
JVM's JIT compiler can't pattern match bytes reversal, so it's worth explicitly delegating to Java Stdlib functions, that are intrinsics candidates. For long values, the new implementation shows 20% perf improvement for reversal itself. Functions depending on it, like readXXXLe or writeXXXLe also show some moderate performance improvement from the change.
- Loading branch information
Showing
5 changed files
with
50 additions
and
12 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
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 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file. | ||
*/ | ||
|
||
package kotlinx.io | ||
|
||
internal actual fun Short.reverseBytes(): Short = reverseBytesCommon() | ||
internal actual fun Int.reverseBytes(): Int = reverseBytesCommon() | ||
internal actual fun Long.reverseBytes(): Long = reverseBytesCommon() |
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 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file. | ||
*/ | ||
|
||
package kotlinx.io | ||
|
||
internal actual fun Short.reverseBytes(): Short = java.lang.Short.reverseBytes(this) | ||
internal actual fun Int.reverseBytes(): Int = java.lang.Integer.reverseBytes(this) | ||
internal actual fun Long.reverseBytes(): Long = java.lang.Long.reverseBytes(this) |
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 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file. | ||
*/ | ||
|
||
package kotlinx.io | ||
|
||
internal actual fun Short.reverseBytes(): Short = reverseBytesCommon() | ||
internal actual fun Int.reverseBytes(): Int = reverseBytesCommon() | ||
internal actual fun Long.reverseBytes(): Long = reverseBytesCommon() |
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 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENCE file. | ||
*/ | ||
|
||
package kotlinx.io | ||
|
||
internal actual fun Short.reverseBytes(): Short = reverseBytesCommon() | ||
internal actual fun Int.reverseBytes(): Int = reverseBytesCommon() | ||
internal actual fun Long.reverseBytes(): Long = reverseBytesCommon() |