Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

  • Replace string.match() with RegExp.exec() for better performance in cases where global flag is not needed
  • This follows the SonarQube rule S6594 recommendation

Changes

  • web/utils/error-parser.ts
  • web/utils/urlValidation.ts
  • web/app/components/tools/mcp/modal.tsx
  • web/app/components/base/ga/index.tsx
  • web/app/components/base/mermaid/index.tsx
  • web/app/components/base/mermaid/utils.ts (using .test() since only boolean check needed)
  • web/app/components/base/date-and-time-picker/utils/dayjs.ts
  • web/app/components/app/configuration/index.tsx
  • web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx
  • web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx

Test plan

  • All existing tests pass (pnpm test)
  • Type check passes (pnpm type-check:tsgo)
  • Lint check passes (pnpm lint:fix)

fixes #25199

Replace string.match() with RegExp.exec() for better performance
in cases where global flag is not needed. This follows the
SonarQube rule S6594 recommendation.

Changes:
- web/utils/error-parser.ts
- web/utils/urlValidation.ts
- web/app/components/tools/mcp/modal.tsx
- web/app/components/base/ga/index.tsx
- web/app/components/base/mermaid/index.tsx
- web/app/components/base/mermaid/utils.ts
- web/app/components/base/date-and-time-picker/utils/dayjs.ts
- web/app/components/app/configuration/index.tsx
- web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx
- web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx

fixes langgenius#25199

Signed-off-by: majiayu000 <1835304752@qq.com>
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. javascript Pull requests that update javascript code labels Dec 31, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @majiayu000, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the codebase by replacing instances of string.match() with RegExp.exec() or RegExp.test() where appropriate. The primary goal is to improve application performance by using more efficient regular expression methods and to adhere to recommended coding standards, specifically SonarQube rule S6594.

Highlights

  • Performance Improvement: Replaced string.match() with RegExp.exec() in various locations for enhanced performance, particularly in cases where the global flag is not required.
  • SonarQube Compliance: The refactoring aligns with SonarQube rule S6594, promoting best practices for regular expression usage and improving code quality.
  • Optimized Boolean Checks: In instances where only a boolean result was needed, RegExp.test() was utilized instead of string.match() for further optimization.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully refactors string.match() to RegExp.exec() for better performance, as intended. The changes are correct and follow the SonarQube recommendation. I've added a few suggestions to further improve maintainability and code clarity by extracting repeated or inline regular expressions into constants and simplifying some of the match-handling logic. These changes also prevent regex re-compilation on every render, which aligns with the performance goals of this PR.

// Extract offset from name format like "-11:00 Niue Time" or "+05:30 India Time"
// Name format is always "{offset}:{minutes} {timezone name}"
const offsetMatch = tzItem.name.match(/^([+-]?\d{1,2}):(\d{2})/)
const offsetMatch = /^([+-]?\d{1,2}):(\d{2})/.exec(tzItem.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve performance and readability, consider defining this regular expression as a constant at the top of the file (e.g., const OFFSET_PATTERN = /^([+-]?\d{1,2}):(\d{2})/;). This prevents it from being recompiled on every call to this function.

.map((line) => {
// Gantt charts have specific syntax needs.
const taskMatch = line.match(/^\s*([^:]+?)\s*:\s*(.*)/)
const taskMatch = /^\s*([^:]+?)\s*:\s*(.*)/.exec(line)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve performance and readability, consider defining this regular expression as a constant outside of the component. This prevents it from being recompiled on every render, which is especially important here since it's inside a map function.

&& !trimmedCode.includes('[object Object]')
&& trimmedCode.split('\n').every(line =>
!(line.includes('-->') && !line.match(/\S+\s*-->\s*\S+/)))
!(line.includes('-->') && !/\S+\s*-->\s*\S+/.test(line)))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve performance and readability, consider defining this regular expression as a constant at the top of the file. This prevents it from being recompiled on every call to this function, which is especially important here since it's inside an every callback.

majiayu000 and others added 4 commits January 1, 2026 00:25
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ech/param-config-content.tsx

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…reply/index.tsx

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jan 5, 2026
asukaminato0721 and others added 2 commits January 5, 2026 22:18
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore/Refactor] use RegExp.exec instead of string.match

2 participants