Skip to content

Commit 4d4db86

Browse files
committed
use shared_ptr for regex::impl
1 parent c67c97c commit 4d4db86

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

private/rdf4cpp/regex/RegexReplacerImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ static std::string translate_rewrite(std::string_view const s) {
7474

7575
} // namespace detail
7676

77-
RegexReplacer::Impl::Impl(Regex::Impl const &regex, std::string_view const rewrite) : regex{&regex},
78-
rewrite{regex.flags.contains(RegexFlag::Literal)
77+
RegexReplacer::Impl::Impl(std::shared_ptr<Regex::Impl> regex, std::string_view const rewrite) : regex{std::move(regex)},
78+
rewrite{this->regex->flags.contains(RegexFlag::Literal)
7979
? rewrite
8080
: detail::translate_rewrite(rewrite)} {
8181
std::string err{};

private/rdf4cpp/regex/RegexReplacerImpl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
namespace rdf4cpp::regex {
88

99
struct RegexReplacer::Impl {
10-
Regex::Impl const *regex;
10+
std::shared_ptr<Regex::Impl> regex;
1111
std::string rewrite;
1212

13-
Impl(Regex::Impl const &regex, std::string_view rewrite);
13+
Impl(std::shared_ptr<Regex::Impl> regex, std::string_view rewrite);
1414
void regex_replace(std::string &str) const noexcept;
1515
};
1616

src/rdf4cpp/regex/Regex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace rdf4cpp::regex {
66

7-
Regex::Regex(std::string_view regex, flag_type const flags) : impl{std::make_unique<Impl>(regex, flags)} {
7+
Regex::Regex(std::string_view regex, flag_type const flags) : impl(std::make_shared<Impl>(regex, flags)) {
88
}
99

1010
Regex::Regex(Regex &&other) noexcept = default;
@@ -20,7 +20,7 @@ bool Regex::regex_search(std::string_view const str) const noexcept {
2020
}
2121

2222
RegexReplacer Regex::make_replacer(std::string_view const rewrite) const {
23-
return RegexReplacer{std::make_unique<RegexReplacer::Impl>(*this->impl, rewrite)};
23+
return RegexReplacer{std::make_shared<RegexReplacer::Impl>(this->impl, rewrite)};
2424
}
2525

2626
} //namespace rdf4cpp::regex

src/rdf4cpp/regex/Regex.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Regex {
1919
friend struct RegexReplacer;
2020

2121
struct Impl;
22-
std::unique_ptr<Impl> impl;
22+
std::shared_ptr<Impl> impl;
2323

2424
public:
2525
/**

src/rdf4cpp/regex/RegexReplacer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace rdf4cpp::regex {
55

6-
RegexReplacer::RegexReplacer(std::unique_ptr<Impl> &&impl) noexcept : impl{std::move(impl)} {
6+
RegexReplacer::RegexReplacer(std::shared_ptr<Impl> &&impl) noexcept : impl{std::move(impl)} {
77
}
88

99
RegexReplacer::RegexReplacer() noexcept = default;

src/rdf4cpp/regex/RegexReplacer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ struct RegexReplacer {
1212
friend struct Regex;
1313

1414
struct Impl;
15-
std::unique_ptr<Impl> impl;
15+
std::shared_ptr<Impl> impl;
1616

17-
explicit RegexReplacer(std::unique_ptr<Impl> &&impl) noexcept;
17+
explicit RegexReplacer(std::shared_ptr<Impl> &&impl) noexcept;
1818
public:
1919
RegexReplacer() noexcept;
2020
RegexReplacer(RegexReplacer &&other) noexcept;

0 commit comments

Comments
 (0)