Skip to content

Simplify std::shared_ptr manipulation inside lexer's ContentSpan - #2252

Closed
Rangi42 wants to merge 1 commit into
gbdev:masterfrom
Rangi42:content-span-ptr
Closed

Rangi42 wants to merge 1 commit into
gbdev:masterfrom
Rangi42:content-span-ptr

Conversation

@Rangi42

@Rangi42 Rangi42 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

C++ std::shared_ptr "can share ownership of an object while storing a pointer to another object" (cppreference). We were taking advantage of this inside makeCapture to have pointers to a captured rept/macro body at some offset inside an owned vector. However, this is arguably nontrivial/surprising use of C++ features. Furthermore, we couldn't use content.ptr = std::make_shared<char[]>(size) (cppreference) because of insufficient platform support (despite being part of C++20, it was added only in gcc 12 and clang 15), so we had to use std::shared_ptr<char[]>(new char[size]). So that will be one more thing I can check off of #2003.

@Rangi42 Rangi42 added this to the 1.0.5 milestone Nov 23, 2026
@Rangi42 Rangi42 added rgbasm This affects RGBASM refactoring This PR is intended to clean up code more than change functionality labels Nov 23, 2026
@Rangi42
Rangi42 requested a review from ISSOtm November 23, 2026 23:33
@Rangi42

Rangi42 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed that this works on Apple OSes older than what CI provides (macOS 11 with clang++ 22, and Mac OS X 10.8 with g++ 14, both available on MacPorts).

@ISSOtm ISSOtm left a comment

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.

I do not like the extra allocation and indirection that this change performs without simplifying the code, so I'd rather not but I won't veto this either.

@Rangi42

Rangi42 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

I do not like the extra allocation and indirection that this change performs without simplifying the code, so I'd rather not but I won't veto this either.

@ISSOtm Can you explain further? What extra allocation? And what would you do differently to simplify this code? Or if you think that using shared_ptr as intended was already simple/idiomatic enough, would you rather leave it as-is?

@ISSOtm

ISSOtm commented Nov 26, 2026

Copy link
Copy Markdown
Member

Right now I don't see this providing a worthwhile improvement, yeah.

@Rangi42 Rangi42 closed this Nov 26, 2026
@Rangi42
Rangi42 deleted the content-span-ptr branch November 26, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring This PR is intended to clean up code more than change functionality rgbasm This affects RGBASM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants