blob: 589c8ad58784964883680e43cc0ee658945f31df [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2017 The Chromium Authors
Samuel Huangfdb2f3a2017-12-20 17:45:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Samuel Huang577ef6c2018-03-13 18:19:345#include "components/zucchini/ensemble_matcher.h"
Samuel Huangfdb2f3a2017-12-20 17:45:146
Peter Kastingccea09832025-01-27 18:38:227#include <algorithm>
Samuel Huangfdb2f3a2017-12-20 17:45:148#include <limits>
Andrew Rayskiy4384ef7d2024-02-28 20:41:589#include <vector>
Samuel Huangfdb2f3a2017-12-20 17:45:1410
11#include "base/logging.h"
Samuel Huangfdb2f3a2017-12-20 17:45:1412
13namespace zucchini {
14
15/******** EnsembleMatcher ********/
16
17EnsembleMatcher::EnsembleMatcher() = default;
18
19EnsembleMatcher::~EnsembleMatcher() = default;
20
21void EnsembleMatcher::Trim() {
Etienne Pierre-Dorayd214e2c2018-03-29 13:33:4622 // Trim rule: If > 1 DEX files are found then ignore all DEX. This is done
23 // because we do not yet support MultiDex, under which contents can move
24 // across file boundary between "old" and "new" archives. When this occurs,
25 // forcing matches of DEX files and patching them separately can result in
26 // larger patches than naive patching.
27 auto is_match_dex = [](const ElementMatch& match) {
28 return match.exe_type() == kExeTypeDex;
29 };
Peter Kastingccea09832025-01-27 18:38:2230 auto num_dex = std::ranges::count_if(matches_, is_match_dex);
Etienne Pierre-Dorayd214e2c2018-03-29 13:33:4631 if (num_dex > 1) {
32 LOG(WARNING) << "Found " << num_dex << " DEX: Ignoring all.";
Andrew Rayskiy4384ef7d2024-02-28 20:41:5833 std::erase_if(matches_, is_match_dex);
Etienne Pierre-Dorayd214e2c2018-03-29 13:33:4634 }
Samuel Huangfdb2f3a2017-12-20 17:45:1435}
36
Samuel Huangfdb2f3a2017-12-20 17:45:1437} // namespace zucchini