1 /*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "src/shared_lib/intern_map.h"
18
19 namespace perfetto {
20 InternMap::InternMap() = default;
21
22 InternMap::~InternMap() = default;
23
FindOrAssign(int32_t type,const void * value,size_t value_size)24 InternMap::FindOrAssignRes InternMap::FindOrAssign(int32_t type,
25 const void* value,
26 size_t value_size) {
27 // This would be more efficient with heterogeneous lookups, but C++17 doesn't
28 // support that.
29 auto* it = map_.Find(Key::NonOwning(type, value, value_size));
30 if (it != nullptr) {
31 return {*it, false};
32 }
33 uint64_t iid = ++last_iid_by_type_[type];
34 it = map_.Insert(Key::Owning(type, value, value_size), iid).first;
35 return {iid, true};
36 }
37
38 } // namespace perfetto
39