-
-
Notifications
You must be signed in to change notification settings - Fork 51
update: use java.util.BitSet on js platform #384
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
Merged
johnynek
merged 11 commits into
typelevel:main
from
i10416:use-java-bitset-from-scalajs-1.9.0#381
Mar 17, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e85b165
update: use java.util.BitSet on js platform
i10416 aad44b1
switch test iteration based on build platform
i10416 7c6097e
put platform check fields back for bincompat
i10416 8a4c6e6
exclude internal api from bincompat issue reports
i10416 bc9599c
resolve conflict
i10416 3168416
tweak
i10416 b74a942
Merge branch 'main' into use-java-bitset-from-scalajs-1.9.0#381
i10416 cbdddc2
rebase change
i10416 2859f0c
supress bincompat wornings for bitsetutils
i10416 74baf57
Merge branch 'main' into use-java-bitset-from-scalajs-1.9.0#381
i10416 e7bf32b
update mima rules
i10416 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
| /* | ||
| * Copyright (c) 2021 Typelevel | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| * this software and associated documentation files (the "Software"), to deal in | ||
| * the Software without restriction, including without limitation the rights to | ||
| * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| * the Software, and to permit persons to whom the Software is furnished to do so, | ||
| * subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| */ | ||
|
|
||
| package cats.parse | ||
|
|
||
| import java.util.BitSet | ||
| private[parse] abstract class BitSetUtilCompat( | ||
| // TODO: Remove isScalaJs/isScalaJvm in next minor version update. See https://github.com/typelevel/cats-parse/issues/391. | ||
| @inline final val isScalaJs: Boolean, | ||
| @inline final val isScalaJvm: Boolean | ||
| ) { | ||
| type Tpe = BitSet | ||
|
|
||
| @inline final def isSet(b: BitSet, idx: Int): Boolean = | ||
| // BitSet can't deal with negatives, so mask those out | ||
| b.get(idx & Int.MaxValue) | ||
|
|
||
| // we require a sorted, nonEmpty, charArray | ||
| def bitSetFor(charArray: Array[Char]): BitSet = { | ||
| val min = charArray(0).toInt | ||
| val bs = new BitSet(charArray(charArray.length - 1).toInt + 1 - min) | ||
| var idx = 0 | ||
| while (idx < charArray.length) { | ||
| bs.set(charArray(idx).toInt - min) | ||
| idx += 1 | ||
| } | ||
|
|
||
| bs | ||
| } | ||
|
|
||
| def isSingleton(t: Tpe): Boolean = t.cardinality() == 1 | ||
|
|
||
| // what are all the Chars in these bitsets | ||
| def union(bs: List[(Int, BitSet)]): Iterable[Char] = | ||
| union(bs.iterator) | ||
|
|
||
| def union(bs: Iterator[(Int, BitSet)]): Iterable[Char] = { | ||
| def toIter(m: Int, bs: BitSet): Iterator[Char] = | ||
| Iterator | ||
| .iterate(0) { m => bs.nextSetBit(m + 1) } | ||
| .takeWhile(_ >= 0) | ||
| .map { i => (m + i).toChar } | ||
|
|
||
| bs.flatMap { case (m, bs) => toIter(m, bs) }.toSet | ||
| } | ||
|
|
||
| def bitSetForRange(count: Int): BitSet = { | ||
| val bs = new BitSet(count) | ||
| bs.flip(0, count) | ||
| bs | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,29 @@ | ||
| import com.typesafe.tools.mima.core.ProblemFilters | ||
| import com.typesafe.tools.mima.core.IncompatibleMethTypeProblem | ||
| import com.typesafe.tools.mima.core.IncompatibleResultTypeProblem | ||
| import com.typesafe.tools.mima.core.DirectMissingMethodProblem | ||
| object MimaExclusionRules { | ||
| val parserImpl = Seq( | ||
| "cats.parse.Parser#Impl.mergeCharIn", | ||
| "cats.parse.Parser#Impl.mergeStrIn", | ||
| "cats.parse.Parser#Impl#CharIn.copy", | ||
| "cats.parse.Parser#Impl#CharIn.apply", | ||
| "cats.parse.Parser#Impl#CharIn.this" | ||
| ).map(ProblemFilters.exclude[IncompatibleMethTypeProblem](_)) ++ Seq( | ||
| "cats.parse.Parser#Impl#StringIn.parseMut", | ||
| "cats.parse.Parser#Impl.stringIn", | ||
| "cats.parse.Parser#Impl#CharIn.copy$default$2", | ||
| "cats.parse.Parser#Impl#CharIn.bitSet", | ||
| "cats.parse.Parser#Impl#CharIn._2" | ||
| ).map(ProblemFilters.exclude[IncompatibleResultTypeProblem](_)) ++ Seq( | ||
| "cats.parse.Parser#Impl.mergeCharIn", | ||
| "cats.parse.Parser#Impl.mergeStrIn" | ||
| ).map(ProblemFilters.exclude[DirectMissingMethodProblem](_)) | ||
| // TODO: Remove these rules in future release. | ||
| val bitSetUtil = Seq( | ||
| "cats.parse.BitSetUtil.isSingleton", | ||
| "cats.parse.BitSetUtil.isSet" | ||
| ).map(ProblemFilters.exclude[IncompatibleMethTypeProblem](_)) ++ Seq( | ||
| "cats.parse.BitSetUtil.bitSetFor" | ||
| ).map(ProblemFilters.exclude[IncompatibleResultTypeProblem](_)) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.