8000 Clean up j.u.regex.* and use the native 'd' flag when available by sjrd · Pull Request #4470 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Clean up j.u.regex.* and use the native 'd' flag when available #4470

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
merged 5 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Regex: Only use subSequence in the region() method.
Previously, the constructor of `Matcher` accepted region params,
but the only call site always used the full string. This commit
confines the use of `subSequence` to the `region()` method.
  • Loading branch information
sjrd committed Jul 9, 2021
commit 0896ff4ef0dc15d4466b06150c0ab2555aef1d85
19 changes: 12 additions & 7 deletions javalib/src/main/scala/java/util/regex/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import scala.annotation.switch
import scala.scalajs.js

final class Matcher private[regex] (
private var pattern0: Pattern, private var input0: CharSequence,
private var regionStart0: Int, private var regionEnd0: Int)
private var pattern0: Pattern, private var input0: CharSequence)
extends AnyRef with MatchResult {

import Matcher._

def pattern(): Pattern = pattern0

// Configuration (updated manually)
private var inputstr = input0.subSequence(regionStart0, regionEnd0).toString
// Region configuration (updated by reset() and region())
private var regionStart0 = 0
private var regionEnd0 = input0.length()
private var inputstr = input0.toString()

// Match result (updated by successful matches)
private var position: Int = 0 // within `inputstr`, not `input0`
Expand Down Expand Up @@ -151,8 +152,12 @@ final class Matcher private[regex] (
this
}

def reset(): Matcher =
region(0, input0.length())
def reset(): Matcher = {
regionStart0 = 0
regionEnd0 = input0.length()
inputstr = input0.toString()
resetMatch()
}

def reset(input: CharSequence): Matcher = {
input0 = input
Expand Down Expand Up @@ -229,7 +234,7 @@ final class Matcher private[regex] (
// Similar difficulties as with hitEnd()
//def requireEnd(): Boolean

// Stub methods for region management
// Region management

def regionStart(): Int = regionStart0
def regionEnd(): Int = regionEnd0
Expand Down
2 changes: 1 addition & 1 deletion javalib/src/main/scala/java/util/regex/Pattern.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ final class Pattern private[regex] (
override def toString(): String = pattern()

def matcher(input: CharSequence): Matcher =
new Matcher(this, input, 0, input.length)
new Matcher(this, input)

def split(input: CharSequence): Array[String] =
split(input, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class LibrarySizeTest {
)

testLinkedSizes(
expectedFastLinkSize = 187486,
expectedFullLinkSizeWithoutClosure = 174649,
expectedFullLinkSizeWithClosure = 31827,
expectedFastLinkSize = 186816,
expectedFullLinkSizeWithoutClosure = 173972,
expectedFullLinkSizeWithClosure = 31629,
classDefs,
moduleInitializers = MainTestModuleInitializers
)
Expand Down
0