From 1db119a8ca55d9a6f19de56cb07f487b415a65fa Mon Sep 17 00:00:00 2001 From: Serge Lamikhov-Center Date: Wed, 12 Nov 2014 18:36:18 +0200 Subject: [PATCH] Refactoring - a nicer code for is_subsequence_of() Conflicts: elf_examples/asm_copy --- elfio/elfio.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/elfio/elfio.hpp b/elfio/elfio.hpp index 23e838c..753d2d7 100644 --- a/elfio/elfio.hpp +++ b/elfio/elfio.hpp @@ -484,19 +484,19 @@ class elfio } //------------------------------------------------------------------------------ - bool is_subsequence_of( segment* seg1, segment* seg2 ) - { - // Return 'true' if sections of seg1 are a subset of sections in seg2 - const std::vector& sections1 = seg1->get_sections(); - const std::vector& sections2 = seg2->get_sections(); - - bool found = std::search( sections2.begin(), sections2.end(), - sections1.begin(), sections1.end() ) - != sections2.end(); - - return found && - ( sections2.size() != 0 ) && - ( sections1.size() != sections2.size() ); + bool is_subsequence_of( segment* seg1, segment* seg2 ) + { + // Return 'true' if sections of seg1 are a subset of sections in seg2 + const std::vector& sections1 = seg1->get_sections(); + const std::vector& sections2 = seg2->get_sections(); + + bool found = false; + if ( sections1.size() < sections2.size() ) { + found = std::includes( sections2.begin(), sections2.end(), + sections1.begin(), sections1.end() ); + } + + return found; } //------------------------------------------------------------------------------