Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted C++ cleanup #102

Merged
merged 10 commits into from
Sep 18, 2023
Merged

Assorted C++ cleanup #102

merged 10 commits into from
Sep 18, 2023

Conversation

mudge
Copy link
Owner

@mudge mudge commented Sep 17, 2023

Try to address some of the items from #59 and improve the C++ code of the extension.

Namely:

  • Replace use of "using" with explicit naming
  • Use references to NamedCapturingGroups, not copies

As RE2's NamedCapturingGroups returns a const reference to its map of
names to indices, use that rather than immediately taking a copy. Switch
to using iterators over the data where possible. Note we don't use auto
for the types as that isn't available when compiling against the oldest
versions of RE2.
Now we only support Ruby 2.6 and later, we can drop the various macros
used to polyfill support for Ruby without RSTRING_LEN, encoding support,
etc.
cpplint complains about the use of a non-const reference, instead
recommending the use of a pointer when the argument will be mutated as
in this case where we're setting various RE2::Options.
To make it clearer what is local to this file and which VALUEs will be
mutated, use static for every function (except Init_re2) and use const
VALUE where possible.
As re2::StringPiece (and absl::string_view in the most recent versions)
can be used as both a std::string and a const char *, there's no need to
create extra strings when we can use a C string directly.
@mudge mudge marked this pull request as ready for review September 17, 2023 20:09
@mudge mudge merged commit e6a52e6 into main Sep 18, 2023
155 checks passed
@mudge mudge deleted the cpp-cleanup branch September 18, 2023 13:28
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