Skip to content

Commit 5e25e27

Browse files
committed
address review comments
1 parent 84563e2 commit 5e25e27

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/utils/common.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ std::string get_current_git_path()
2424
// ->check(CLI::ExistingDirectory | CLI::NonexistentPath)
2525
// ->default_val(std::filesystem::current_path());
2626

27-
git_strarray_wrapper::git_strarray_wrapper(std::vector<std::string> m_patterns)
28-
: m_patterns(std::move(m_patterns))
27+
git_strarray_wrapper::git_strarray_wrapper(std::vector<std::string> patterns)
28+
: m_patterns(std::move(patterns))
2929
{
3030
init_str_array();
3131
}
@@ -34,23 +34,40 @@ git_strarray_wrapper::git_strarray_wrapper(git_strarray_wrapper&& rhs)
3434
: m_patterns(std::move(rhs.m_patterns))
3535
{
3636
init_str_array();
37+
rhs.reset_str_array();
38+
}
39+
40+
git_strarray_wrapper& git_strarray_wrapper::operator=(git_strarray_wrapper&& rhs)
41+
{
42+
using std::swap;
43+
swap(m_patterns, rhs.m_patterns);
44+
swap(m_array.strings, rhs.m_array.strings);
45+
swap(m_array.count, rhs.m_array.count);
46+
return *this;
3747
}
3848

3949
git_strarray_wrapper::~git_strarray_wrapper()
4050
{
41-
delete[] m_array.strings;
51+
reset_str_array();
4252
}
4353

4454
git_strarray_wrapper::operator git_strarray*()
4555
{
4656
return &m_array;
4757
}
4858

59+
void git_strarray_wrapper::reset_str_array()
60+
{
61+
delete[] m_array.strings;
62+
m_array={nullptr, 0};
63+
}
64+
4965
void git_strarray_wrapper::init_str_array()
5066
{
51-
git_strarray array{new char*[m_patterns.size()], m_patterns.size()};
67+
m_array.strings = new char*[m_patterns.size()];
68+
m_array.count = m_patterns.size();
5269
for (size_t i=0; i<m_patterns.size(); ++i)
5370
{
54-
array.strings[i] = const_cast<char*>(m_patterns[i].c_str());
71+
m_array.strings[i] = const_cast<char*>(m_patterns[i].c_str());
5572
}
5673
}

src/utils/common.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ class git_strarray_wrapper
6868
: m_patterns{}
6969
, m_array{nullptr, 0}
7070
{}
71-
git_strarray_wrapper(std::vector<std::string> m_patterns);
71+
git_strarray_wrapper(std::vector<std::string> patterns);
7272

7373
git_strarray_wrapper(const git_strarray_wrapper&) = delete;
7474
git_strarray_wrapper& operator=(const git_strarray_wrapper&) = delete;
7575

7676
git_strarray_wrapper(git_strarray_wrapper&& rhs);
77+
git_strarray_wrapper& operator=(git_strarray_wrapper&&);
7778

7879
~git_strarray_wrapper();
7980

@@ -83,5 +84,6 @@ class git_strarray_wrapper
8384
std::vector<std::string> m_patterns;
8485
git_strarray m_array;
8586

87+
void reset_str_array();
8688
void init_str_array();
8789
};

0 commit comments

Comments
 (0)