Skip to content

refactor: extract magic cloning to clone_magic() helper#143

Draft
Koan-Bot wants to merge 1 commit into
garu:masterfrom
Koan-Bot:koan.atoomic/refactor-extract-clone-magic
Draft

refactor: extract magic cloning to clone_magic() helper#143
Koan-Bot wants to merge 1 commit into
garu:masterfrom
Koan-Bot:koan.atoomic/refactor-extract-clone-magic

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

What

Extract the 107-line magic cloning block from sv_clone() into a dedicated clone_magic() helper function.

Why

sv_clone() is ~390 lines with multiple concerns interleaved. The magic cloning section (ext magic dispatch, threads::shared stripping, tie detection, qr vtable nulling, mg_ptr copying) is a self-contained block that can be cleanly separated. This makes sv_clone easier to read and reason about.

How

  • New static int clone_magic(SV *ref, SV *clone, HV *hseen, int rdepth, AV *weakrefs) function
  • Returns the tie-magic count so sv_clone can still skip direct HV/AV iteration for tied containers
  • Zero behavior change — the code is moved verbatim, only indentation adjusted
  • Forward declaration added alongside the other static function declarations

Testing

Full test suite passes (28 test files). Build clean with no warnings.

🤖 Generated with Claude Code


Quality Report

Changes: 1 file changed, 121 insertions(+), 108 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The magic cloning logic in sv_clone() was a 107-line inline block that
handled ext magic, threads::shared stripping, tie detection, qr vtable
nulling, and mg_ptr copying.  Extracting it to clone_magic() makes
sv_clone() significantly shorter and easier to follow, with zero
behavior change.

The new function returns the tie-magic count so sv_clone() can still
skip direct HV/AV element iteration for tied containers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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