Skip to content

<random>: Avoid copying vectors in distribution comparisons - #6454

Open
A. Jiang (frederick-vs-ja) wants to merge 1 commit into
microsoft:mainfrom
frederick-vs-ja:operator-eq-no-copy-vector
Open

A. Jiang (frederick-vs-ja) wants to merge 1 commit into
microsoft:mainfrom
frederick-vs-ja:operator-eq-no-copy-vector

Conversation

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

It is just unreasonable to perform dynamic allocation in such comparisons.

Ideally, these operator==s (and corresponding operator!= until C++20) should also be noexcept, but we haven't strengthened exception specification for vector's operator== yet.

It is just unreasonable to perform dynamic allocation in such
comparisons.

Ideally, these `operator==`s (and corresponding
`operator!=` until C++20) should also be `noexcept`, but we haven't
strengthened exception specification for `vector`'s `operator==` yet.
Copilot AI balanced review requested due to automatic review settings September 17, 2026 07:26
@frederick-vs-ja
A. Jiang (frederick-vs-ja) requested a review from a team as a code owner September 17, 2026 07:26
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Sep 17, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The direct comparisons preserve behavior while eliminating unnecessary allocations.

Pull request overview

Optimizes random distribution equality comparisons by avoiding temporary param_type objects and their vector allocations.

Changes:

  • Compares stored parameter objects directly for three vector-backed distributions.
  • Preserves existing equality semantics.
File summaries
File Description
stl/inc/random Avoids parameter-vector copies in distribution comparisons.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread stl/inc/random

_NODISCARD friend bool operator==(const discrete_distribution& _Left, const discrete_distribution& _Right) {
return _Left.param() == _Right.param();
return _Left._Par == _Right._Par;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These might be the only ones where it matters in release mode, but IMO I think we should now be implementing all of the distribution operator== by directly inspecting _Par instead of calling param(). It's more consistent throughout the file, and happens to improve debugging and debug codegen.

@github-project-automation github-project-automation Bot moved this from Initial Review to Work In Progress in STL Code Reviews Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster

Projects

Status: Work In Progress

Development

Successfully merging this pull request may close these issues.

3 participants