Commit 7475b353d0d19e68c9a0d73aabad58606213815a
1 parent
925ce4e6
In QPDFArgParser refactor argv handling to use `std::vector` instead of shared pointers.
Replaces `std::shared_ptr<char const*>` with `std::vector<char const*>` for `argv` and `bash_argv` processing. This simplifies memory management, improves code clarity, and ensures better alignment with modern C++ practices. Updated all associated logic to handle `std::vector` operations efficiently.
Showing
2 changed files
with
12 additions
and
12 deletions
libqpdf/QPDFArgParser.cc
| ... | ... | @@ -257,13 +257,13 @@ QPDFArgParser::handleArgFileArguments() |
| 257 | 257 | m->new_argv.emplace_back(m->argv[i]); |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | - m->argv_ph = QUtil::make_shared_array<char const*>(1 + m->new_argv.size()); | |
| 261 | - for (size_t i = 0; i < m->new_argv.size(); ++i) { | |
| 262 | - m->argv_ph.get()[i] = m->new_argv.at(i).data(); | |
| 260 | + m->argv_ph.reserve(1 + m->new_argv.size()); | |
| 261 | + for (auto const& a: m->new_argv) { | |
| 262 | + m->argv_ph.push_back(a.data()); | |
| 263 | 263 | } |
| 264 | 264 | m->argc = QIntC::to_int(m->new_argv.size()); |
| 265 | - m->argv_ph.get()[m->argc] = nullptr; | |
| 266 | - m->argv = m->argv_ph.get(); | |
| 265 | + m->argv_ph.push_back(nullptr); | |
| 266 | + m->argv = m->argv_ph.data(); | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | void |
| ... | ... | @@ -329,13 +329,13 @@ QPDFArgParser::handleBashArguments() |
| 329 | 329 | m->bash_argv.emplace_back(m->argv[0]); |
| 330 | 330 | } |
| 331 | 331 | // Explicitly discard any non-space-terminated word. The "current word" is handled specially. |
| 332 | - m->bash_argv_ph = QUtil::make_shared_array<char const*>(1 + m->bash_argv.size()); | |
| 333 | - for (size_t i = 0; i < m->bash_argv.size(); ++i) { | |
| 334 | - m->bash_argv_ph.get()[i] = m->bash_argv.at(i).data(); | |
| 332 | + m->bash_argv_ph.reserve(1 + m->bash_argv.size()); | |
| 333 | + for (auto const& a: m->bash_argv) { | |
| 334 | + m->bash_argv_ph.push_back(a.data()); | |
| 335 | 335 | } |
| 336 | 336 | m->argc = QIntC::to_int(m->bash_argv.size()); |
| 337 | - m->bash_argv_ph.get()[m->argc] = nullptr; | |
| 338 | - m->argv = m->bash_argv_ph.get(); | |
| 337 | + m->bash_argv_ph.push_back(nullptr); | |
| 338 | + m->argv = m->bash_argv_ph.data(); | |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | void | ... | ... |
libqpdf/qpdf/QPDFArgParser.hh
| ... | ... | @@ -221,8 +221,8 @@ class QPDFArgParser |
| 221 | 221 | bare_arg_handler_t final_check_handler; |
| 222 | 222 | std::vector<std::string> new_argv; |
| 223 | 223 | std::vector<std::string> bash_argv; |
| 224 | - std::shared_ptr<char const*> argv_ph; | |
| 225 | - std::shared_ptr<char const*> bash_argv_ph; | |
| 224 | + std::vector<char const*> argv_ph; | |
| 225 | + std::vector<char const*> bash_argv_ph; | |
| 226 | 226 | std::map<std::string, HelpTopic> help_topics; |
| 227 | 227 | std::map<std::string, HelpTopic> option_help; |
| 228 | 228 | std::string help_footer; | ... | ... |