Skip to content

Fix #3280: Count capturing groups independently on find. #3468

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 1 commit into from
Oct 15, 2018
Merged

Fix #3280: Count capturing groups independently on find. #3468

merged 1 commit into from
Oct 15, 2018

Conversation

neVERberleRfellerER
Copy link
Contributor

@neVERberleRfellerER neVERberleRfellerER commented Oct 12, 2018

Since
https://www.ecma-international.org/ecma-262/6.0/#sec-regexpbuiltinexec
points 19 nad 20 are always hit and set result size to NcapturingParens+1 and
https://www.ecma-international.org/ecma-262/6.0/#sec-notation
states that "NcapturingParens is the total number of left capturing parentheses" then it should be safe to create always-matching regexp by prepending "|" and getting group count from resulting successful match.

Fixes #3280

@neVERberleRfellerER
Copy link
Contributor Author

neVERberleRfellerER commented Oct 12, 2018

UPDATE: Nevermind. I have checked generic Privacy Policy again and it actually applies to all sites operated by Lightbend and is pretty clear otherwise. I have signed CLA

I am checking out your CLA but I am slightly confused. I guess it wants my real name, but it is not clear whether Ligtbend's "Privacy policy" applies to data gathered in CLA or if CLA is separate and gathered data are never disclosed and used just in case of "problems". Also it's not clear, if Lightbend can access the submitted data since CLA only mentions EPFL but no Lightbend or third-parties (in context of data access) in general, but form is submitted on Lighbend's website. Could you give me answer to at least that part with full name sharing with third-parties?

@neVERberleRfellerER
Copy link
Contributor Author

I did sign the CLA.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR. Very cool fix!

I have a few comments below. Also, could you include the issue being fixed in the commit message, as follows:

Fix #3280: Count capturing groups independently on find.

to follow our commit message guide.

case Some(n) => n

case None =>
val groupCountPattern = Pattern.compile("|" + pattern0.jsPattern)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before using your idea, it would be nice to test the case if (lastMatch != null), and in that case directly use lastMatch.length - 1. This should hopefully be common case, and will be faster than creating a new RegExp and running a dummy query on it.


case None =>
val groupCountPattern = Pattern.compile("|" + pattern0.jsPattern)
val groupCountRegex = groupCountPattern.newJSRegExp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the Pattern.compile step in this case. Just do

val groupCountRegex = new js.RegExp("|" + pattern0.jsPattern)

this will be faster. Flags are irrelevant, and pattern0.jsPattern has already been processed for in-pattern flags, so Pattern.compile is going to do work for nothing.

@gzm0
Copy link
Contributor

gzm0 commented Oct 12, 2018

I guess it wants my real name.

Hum, just to make sure if you are concerned about your real name: There is a very real seeming name in your git commit metadata which is publicly visible.

@neVERberleRfellerER
Copy link
Contributor Author

@gzm0 I know. I was just concerned that it wants real name without any privacy agreement (which was oversight on my side). Just because I use my real name on github does not mean that I automatically want to "give" my real name to another company when I don't know what they are going to use it for, especially when CLA actually mentions only EPFL (which I have no problem with). It's purely ideological problem on my side.

@neVERberleRfellerER neVERberleRfellerER changed the title Count capturing groups independently on find Fix #3280: Count capturing groups independently on find. Oct 13, 2018
def groupCount(): Int = ensureLastMatch.length-1
def groupCount(): Int = {
if (lastMatch != null) lastMatch.length-1
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! One tiny remaining detail: could you format the above as

if (lastMatch != null) {
  lastMatch.length-1
} else {
  ...

to follow our if/else coding style which demands that both branches of an if/else must have {}, or none of them has braces.

Good to merge after that!

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@sjrd sjrd merged commit de34cee into scala-js:0.6.x Oct 15, 2018
@neVERberleRfellerER neVERberleRfellerER deleted the fix-matcher-group-count branch October 18, 2018 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants