Skip to content

Replace ptr = ptr.offset(1) increment patterns with in-place pointer arithmetic#96

Merged
nunoplopes merged 2 commits into
masterfrom
copilot/replace-pointer-increment-patterns
May 13, 2026
Merged

Replace ptr = ptr.offset(1) increment patterns with in-place pointer arithmetic#96
nunoplopes merged 2 commits into
masterfrom
copilot/replace-pointer-increment-patterns

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

This change removes inefficient pointer-increment assignments that rebuilt pointers via offset(1) and standardizes them to in-place increments (+= 1) in non-test Rust code. Scope is limited to production/runtime and rule output sources; tests/ remains untouched.

  • libcc2rs runtime updates

    • Updated pointer progression in:
      • libcc2rs/src/rc.rs (StringIterator)
      • libcc2rs/src/inc.rs (unsafe prefix/postfix increment trait impls for raw pointers)
      • libcc2rs/src/io.rs (fread / fread_unsafe byte-copy loops)
  • Rule output source updates

    • Updated generated-rule Rust sources to use in-place pointer increments:
      • rules/stdio/tgt_refcount.rs
      • rules/stdio/tgt_unsafe.rs
      • rules/algorithm/tgt_unsafe.rs
  • Pattern normalization

    • Canonical replacement applied where variable self-assignment matched pointer increment via offset(1):
// before
ptr = ptr.offset(1);

// after
ptr += 1;

Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/4292d6f5-f28a-4fb3-9f45-3a67ee6f91c7

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
@nunoplopes nunoplopes marked this pull request as ready for review May 13, 2026 20:33
@nunoplopes nunoplopes merged commit 0365227 into master May 13, 2026
9 checks passed
@nunoplopes nunoplopes deleted the copilot/replace-pointer-increment-patterns branch May 13, 2026 20:52
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.

2 participants