Skip to content

refactor: Move insertToken's per-page step onto NFTokenPageEntry - #8409

Open
mvadari wants to merge 4 commits into
mvadari/rearch/nftokenpage-findTokenAndPagefrom
mvadari/rearch/nftokenpage-insertToken
Open

mvadari wants to merge 4 commits into
mvadari/rearch/nftokenpage-findTokenAndPagefrom
mvadari/rearch/nftokenpage-insertToken

Conversation

@mvadari

@mvadari mvadari commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Adds the writable member NFTokenPageEntry::insertToken(STObject&&): it adds the token to this page's NFTokens array, sorts the array with nft::compareTokens, and updates the page. nft::insertToken(view, owner, nft) stays a free function because it finds or creates (and may split) the page first; it now calls the member. The member body is in the new src/libxrpl/ledger/entries/NFTokenPageEntry.cpp with explicit instantiation. The header now includes STArray.h (with IWYU pragma: keep) because explicit instantiation also instantiates the inline findToken(), which iterates an STArray.

Context of Change

Part of the Wrapped SLEs migration (design: step 2/3 of #7886). The per-page insert now lives on the typed, writable page wrapper, so the compiler rejects it on a read-only view or an SLE of another type. Pure refactor: no amendment, no behavior change; any observable difference is a bug.

Stacked on #8400; review only the last commit. The commit before it is a cherry-pick of the MSVC C4661 fix from #8357 (extern template in the SLEBase gtest). It is needed because this PR adds explicit instantiation for NFTokenPageEntry, and it drops out when #8357 merges.

This PR was fully written by AI (Claude Code) under human direction; the human author reviewed the diff.

API Impact

  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)

Test Plan

Compile-checked (clang++ -fsyntax-only, project flags) the new NFTokenPageEntry.cpp, NFTokenHelpers.cpp, and every .cpp that includes NFTokenPageEntry.h or NFTokenHelpers.h (14/14). clang-tidy (including the standalone header check) and pre-commit are clean. No new tests. CI runs the full unit test suite.

🤖 Generated with Claude Code

@ripple-ai-reviewer ripple-ai-reviewer Bot 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.

Clean, mechanical refactor that moves the per-page NFT insertion logic from the free function nft::insertToken onto the new NFTokenPageEntry::insertToken member, with an explicit instantiation in a new .cpp. The moved logic (push, sort via nft::compareTokens, setFieldArray, update()) is a faithful copy of the original code, the call site in NFTokenHelpers.cpp correctly delegates to the new member, and the SLEBase.cpp test macro change (definitions → extern declarations) is explained by the accompanying MSVC C4661 cherry-pick needed once an entry gains an out-of-line member body. No behavioral changes or correctness issues found in the added lines.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mvadari
mvadari force-pushed the mvadari/rearch/nftokenpage-insertToken branch from 055dc6d to 86b670e Compare September 30, 2026 17:40
@mvadari
mvadari added this pull request to stack #8443 September 30, 2026 17:40

@ripple-ai-reviewer ripple-ai-reviewer Bot 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.

Reviewed the last commit (NFTokenPageEntry.h/.cpp and NFTokenHelpers.cpp changes) as instructed; the SLEBase.cpp diff belongs to the separately cherry-picked, already-reviewed MSVC fix and was left out of scope. The refactor moves the per-page insert logic into NFTokenPageEntry::insertToken verbatim (same field access, sort comparator, and update() call), and NFTokenHelpers.cpp's free function now just delegates to it. I traced the logic carefully for behavioral drift (order of pushBack/sort/setFieldArray/update, move semantics, qualification of compareTokens) and found it to be an exact, faithful move with no observable change. No correctness, security, or resource issues found in the changed lines.

@mvadari
mvadari force-pushed the mvadari/rearch/nftokenpage-insertToken branch from 86b670e to ff3ccff Compare October 5, 2026 12:50

@ripple-ai-reviewer ripple-ai-reviewer Bot 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.

This is a clean, mechanical refactor that moves the per-page NFToken insertion logic from the free function nft::insertToken onto the new NFTokenPageEntry<ViewT>::insertToken member, gated by requires Base::kIsWritable. The moved logic (push, sort via nft::compareTokens, set field array, update) is byte-for-byte equivalent to the original, the new .cpp correctly qualifies nft::compareTokens since it's now outside the nft namespace, and the explicit instantiations for ReadView/ApplyView are consistent with the existing pattern used for findToken in the same header. The SLEBase.cpp change is explicitly called out as an unrelated cherry-picked MSVC fix (#8357) and out of scope per the PR description, so it was not reviewed. No correctness, security, or resource-management issues found in the added lines.

@ripple-ai-reviewer ripple-ai-reviewer Bot 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.

Clean, well-scoped refactor that moves the per-page NFToken insert logic onto NFTokenPageEntry::insertToken, gated by requires Base::kIsWritable so it can't be called on a read-only view. The free function nft::insertToken now just delegates to the new member, and the SLEBase test instrumentation was reworked to avoid double explicit-instantiation (MSVC C4661). The logic is a direct move of the existing code with no behavior change, and the explicit-instantiation/constraint interaction looks correct for ReadView vs ApplyView. Only a minor, non-blocking observation below.

@mvadari
mvadari force-pushed the mvadari/rearch/nftokenpage-insertToken branch from 39ccc00 to 57da670 Compare October 5, 2026 14:47

@ripple-ai-reviewer ripple-ai-reviewer Bot 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.

Clean, mechanical refactor that moves the per-page NFToken insert logic from the free function nft::insertToken onto the new NFTokenPageEntry::insertToken member, with the body relocated to a new .cpp and explicit template instantiation for both ReadView and ApplyView. The new member's logic is a verbatim move of the original inline block (push, sort via nft::compareTokens, set field array, update), and the call site in NFTokenHelpers.cpp is updated accordingly — no behavioral change is apparent. The requires Base::kIsWritable constraint on a non-template member of a class template, paired with explicit instantiation for both view types, is a known C++20 pattern (constrained member functions) and appears consistent with how this codebase already structures its writable-only entry members, so it's not flagged as risky. The companion SLEBase.cpp test change is explicitly called out in the MR description as a cherry-picked prep commit from a different PR and was only skimmed accordingly. No correctness, security, or consistency issues were found in the changed lines.

nft::insertToken() first finds or creates the page for the token (and
may split a full page), then adds the token to that page's NFTokens
array, sorts it, and updates the page. The second part only needs the
page, so it becomes NFTokenPageEntry::insertToken(STObject&&). The
free function keeps the page lookup and calls the member.

The member body uses nft::compareTokens(), so it goes into a new
NFTokenPageEntry.cpp with explicit instantiation. The header now
includes STArray.h because the explicit instantiation also
instantiates the inline findToken(), which iterates an STArray.

No behavior change.
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@mvadari
mvadari force-pushed the mvadari/rearch/nftokenpage-insertToken branch from 57da670 to fc57bad Compare November 10, 2026 01:00
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

…ri/rearch/nftokenpage-insertToken

# Conflicts:
#	src/libxrpl/ledger/helpers/NFTokenHelpers.cpp

This branch has not been deployed

No deployments
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.

1 participant