Patch Detail
Show a patch.
GET /api/1.1/patches/425/?format=api
{ "id": 425, "url": "https://patchwork.libcamera.org/api/1.1/patches/425/?format=api", "web_url": "https://patchwork.libcamera.org/patch/425/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190128004109.25860-5-niklas.soderlund@ragnatech.se>", "date": "2019-01-28T00:41:07", "name": "[libcamera-devel,4/6] cam: options: remove OptionsParser::options_", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b05a1b0f09ef8af6eba28022b66a5261e0f02e49", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/425/mbox/", "series": [ { "id": 149, "url": "https://patchwork.libcamera.org/api/1.1/series/149/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=149", "date": "2019-01-28T00:41:03", "name": "cam: add --format option to configure a stream", "version": 1, "mbox": "https://patchwork.libcamera.org/series/149/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/425/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/425/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BD0A60DBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Jan 2019 01:41:33 +0100 (CET)", "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 67fa1ef5-2295-11e9-911a-0050569116f7;\n\tMon, 28 Jan 2019 01:41:10 +0100 (CET)" ], "X-Halon-ID": "67fa1ef5-2295-11e9-911a-0050569116f7", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 28 Jan 2019 01:41:07 +0100", "Message-Id": "<20190128004109.25860-5-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20190128004109.25860-1-niklas.soderlund@ragnatech.se>", "References": "<20190128004109.25860-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 4/6] cam: options: remove\n\tOptionsParser::options_", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "X-List-Received-Date": "Mon, 28 Jan 2019 00:41:33 -0000" }, "content": "It's unsafe to keep a pointer to an object inside a vector if one keeps\nadding and modifying the vectors content. There are also little need to\nkeep the two data structures around when one map can solve the problem.\nRemove the vector and update all loops to iterate over the map instead\nof the vector.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/options.cpp | 18 +++++++++++-------\n src/cam/options.h | 3 +--\n 2 files changed, 12 insertions(+), 9 deletions(-)", "diff": "diff --git a/src/cam/options.cpp b/src/cam/options.cpp\nindex c9ca017b4cf3fa3d..d3bff1cd897a5cfb 100644\n--- a/src/cam/options.cpp\n+++ b/src/cam/options.cpp\n@@ -30,8 +30,8 @@ bool OptionsParser::addOption(int opt, const char *help, const char *name,\n \tif (optionsMap_.find(opt) != optionsMap_.end())\n \t\treturn false;\n \n-\toptions_.push_back(Option({ opt, name, argument, argumentName, help }));\n-\toptionsMap_[opt] = &options_.back();\n+\toptionsMap_[opt] = Option({ opt, name, argument, argumentName, help });\n+\n \treturn true;\n }\n \n@@ -43,14 +43,16 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv)\n \t * Allocate short and long options arrays large enough to contain all\n \t * options.\n \t */\n-\tchar shortOptions[options_.size() * 3 + 2] = {};\n-\tstruct option longOptions[options_.size() + 1] = {};\n+\tchar shortOptions[optionsMap_.size() * 3 + 2] = {};\n+\tstruct option longOptions[optionsMap_.size() + 1] = {};\n \tunsigned int ids = 0;\n \tunsigned int idl = 0;\n \n \tshortOptions[ids++] = ':';\n \n-\tfor (const Option &option : options_) {\n+\tfor (auto const &iter : optionsMap_) {\n+\t\tconst Option &option = iter.second;\n+\n \t\tif (option.hasShortOption()) {\n \t\t\tshortOptions[ids++] = option.opt;\n \t\t\tif (option.argument != ArgumentNone)\n@@ -112,7 +114,8 @@ void OptionsParser::usage()\n \n \tunsigned int indent = 0;\n \n-\tfor (const Option &option : options_) {\n+\tfor (auto const &iter : optionsMap_) {\n+\t\tconst Option &option = iter.second;\n \t\tunsigned int length = 14;\n \t\tif (option.hasLongOption())\n \t\t\tlength += 2 + strlen(option.name);\n@@ -127,7 +130,8 @@ void OptionsParser::usage()\n \n \tindent = (indent + 7) / 8 * 8;\n \n-\tfor (const Option &option : options_) {\n+\tfor (auto const &iter : optionsMap_) {\n+\t\tconst Option &option = iter.second;\n \t\tstd::string argument;\n \t\tif (option.hasShortOption())\n \t\t\targument = std::string(\" -\")\ndiff --git a/src/cam/options.h b/src/cam/options.h\nindex dfb7fcc9f6fa3324..cb7286a0a8005579 100644\n--- a/src/cam/options.h\n+++ b/src/cam/options.h\n@@ -57,8 +57,7 @@ private:\n \t\tbool hasLongOption() const { return name != nullptr; }\n \t};\n \n-\tstd::vector<Option> options_;\n-\tstd::map<unsigned int, Option *> optionsMap_;\n+\tstd::map<unsigned int, Option> optionsMap_;\n };\n \n #endif /* __CAM_OPTIONS_H__ */\n", "prefixes": [ "libcamera-devel", "4/6" ] }