From 221c3146257fe2e3d2fde46a21f7775004f40049 Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 24 Feb 2016 23:13:16 +0100 Subject: [PATCH] ModificationTagsHandler: small optimization --- src/tags_handlers/modification_tags_handler.cc | 3 +++ tests/tags_handlers/modification_tags_handler_test.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/tags_handlers/modification_tags_handler.cc b/src/tags_handlers/modification_tags_handler.cc index 6aab3a0..8801d22 100644 --- a/src/tags_handlers/modification_tags_handler.cc +++ b/src/tags_handlers/modification_tags_handler.cc @@ -22,6 +22,9 @@ std::string ModificationTagsHandler::get_tag_value() const bool ModificationTagsHandler::edit_impl(Tags &tags) { + if (tags.contains(tag_key) && tags.get(tag_key) == tag_value) + return false; + tags.set(tag_key, tag_value); return true; } diff --git a/tests/tags_handlers/modification_tags_handler_test.cc b/tests/tags_handlers/modification_tags_handler_test.cc index 9665796..84340ca 100644 --- a/tests/tags_handlers/modification_tags_handler_test.cc +++ b/tests/tags_handlers/modification_tags_handler_test.cc @@ -27,4 +27,7 @@ TEST_CASE("Modification tags handler test") REQUIRE(handler2.edit(streamno, tags)); REQUIRE(tags.get_all().size() == 2); REQUIRE(tags.get(other_tag_key) == new_value); + + // setting existing keys reports no modifications if values are the same + REQUIRE(!handler2.edit(streamno, tags)); }