Skip to content

fix: Clean up countInstances - #24890

Merged
mcollovati merged 2 commits into
mainfrom
issues/9264-ineffective-count
Jul 2, 2026
Merged

mcollovati merged 2 commits into
mainfrom
issues/9264-ineffective-count

Conversation

@caalador

@caalador caalador commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Make count instances more effective
by not using split that compiles
a pattern and generates an array
for each invocation.

fixes #9264

Make count instances more effective
by not using split that compiles
a pattern and generates an array
for each invocation.

fixes #9264
@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 456 files  ±0   1 456 suites  ±0   1h 29m 41s ⏱️ + 2m 4s
10 301 tests ±0  10 233 ✅ ±0  68 💤 ±0  0 ❌ ±0 
10 773 runs  ±0  10 704 ✅ ±0  69 💤 ±0  0 ❌ ±0 

Results for commit 78483eb. ± Comparison against base commit 557bca0.

♻️ This comment has been updated with latest results.

@mcollovati

Copy link
Copy Markdown
Collaborator

It looks like the new implementation is off by one compared to split
If I run split and the new function against the same input I get different results:

jshell> countInstances("a:b:c:e", ":")
$2 ==> 3

jshell> "a:b:c:e".split(":", -1)
$3 ==> String[4] { "a", "b", "c", "e" }

jshell> "a:b:c:e:f:g:h".split(":",-1)
$8 ==> String[7] { "a", "b", "c", "e", "f", "g", "h" }

jshell> countInstances("a:b:c:e:f:g:h", ":")
$9 ==> 6

@caalador

caalador commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

The original is split(value, -1).length - 1; so it takes away one from the array length making it match the new implementation

@mcollovati

Copy link
Copy Markdown
Collaborator

The original is split(value, -1).length - 1; so it takes away one from the array length making it match the new implementation

Ah, right. My bad. The method name confused me.

@mcollovati

Copy link
Copy Markdown
Collaborator

I wonder if we should add a comment to prevent someone like me from breaking the logic in the future 😄

@caalador

caalador commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I'll think about a descriptive javadoc to explain what is counted

@caalador
caalador requested a review from mcollovati July 2, 2026 05:58
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mcollovati
mcollovati added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit 9977f32 Jul 2, 2026
33 of 34 checks passed
@mcollovati
mcollovati deleted the issues/9264-ineffective-count branch July 2, 2026 06:33
vaadin-bot added a commit that referenced this pull request Jul 2, 2026
This PR cherry-picks changes from the original PR #24890 to branch
24.10.
---
#### Original PR description
> Make count instances more effective
> by not using split that compiles
> a pattern and generates an array
> for each invocation.
> 
> fixes #9264
>

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
vaadin-bot added a commit that referenced this pull request Jul 2, 2026
This PR cherry-picks changes from the original PR #24890 to branch 25.1.
---
#### Original PR description
> Make count instances more effective
> by not using split that compiles
> a pattern and generates an array
> for each invocation.
> 
> fixes #9264
>

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
vaadin-bot added a commit that referenced this pull request Jul 2, 2026
This PR cherry-picks changes from the original PR #24890 to branch 25.2.
---
#### Original PR description
> Make count instances more effective
> by not using split that compiles
> a pattern and generates an array
> for each invocation.
> 
> fixes #9264
>

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeploymentConfigurationFactory.countInstances(): Ineffective way to count substrings

3 participants