Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42ae61e5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libprocessgroup: Make GetProfile() and GetAttribute() more efficient" am: 56183d87

parents 314c07f7 56183d87
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -786,7 +786,7 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) {
    return true;
}

TaskProfile* TaskProfiles::GetProfile(const std::string& name) const {
TaskProfile* TaskProfiles::GetProfile(std::string_view name) const {
    auto iter = profiles_.find(name);

    if (iter != profiles_.end()) {
@@ -795,7 +795,7 @@ TaskProfile* TaskProfiles::GetProfile(const std::string& name) const {
    return nullptr;
}

const IProfileAttribute* TaskProfiles::GetAttribute(const std::string& name) const {
const IProfileAttribute* TaskProfiles::GetAttribute(std::string_view name) const {
    auto iter = attributes_.find(name);

    if (iter != attributes_.end()) {
+6 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <map>
#include <mutex>
#include <string>
#include <string_view>
#include <vector>

#include <android-base/unique_fd.h>
@@ -206,18 +207,18 @@ class TaskProfiles {
    // Should be used by all users
    static TaskProfiles& GetInstance();

    TaskProfile* GetProfile(const std::string& name) const;
    const IProfileAttribute* GetAttribute(const std::string& name) const;
    TaskProfile* GetProfile(std::string_view name) const;
    const IProfileAttribute* GetAttribute(std::string_view name) const;
    void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const;
    bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles,
                            bool use_fd_cache);
    bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache);

  private:
    std::map<std::string, std::shared_ptr<TaskProfile>> profiles_;
    std::map<std::string, std::unique_ptr<IProfileAttribute>> attributes_;

    TaskProfiles();

    bool Load(const CgroupMap& cg_map, const std::string& file_name);

    std::map<std::string, std::shared_ptr<TaskProfile>, std::less<>> profiles_;
    std::map<std::string, std::unique_ptr<IProfileAttribute>, std::less<>> attributes_;
};