|
66 | 66 |
|
67 | 67 | namespace { |
68 | 68 |
|
| 69 | +// Hash functor for std::vector<T> to enable use as keys in UnorderedMap. |
| 70 | +// Uses FNV-1a-inspired hash combining over the raw element values. |
| 71 | +template <typename T> |
| 72 | +struct VectorHash { |
| 73 | + size_t operator()(const std::vector<T>& v) const { |
| 74 | + size_t seed = v.size(); |
| 75 | + for (const auto& elem : v) { |
| 76 | + seed ^= std::hash<T>{}(elem) + 0x9e3779b9 + (seed << 6) + (seed >> 2); |
| 77 | + } |
| 78 | + return seed; |
| 79 | + } |
| 80 | +}; |
| 81 | + |
69 | 82 | template <class T, class U> |
70 | 83 | class CustomSort { |
71 | 84 | private: |
@@ -1135,7 +1148,8 @@ void DexOutput::unique_annotations(annomap_t& annomap, |
1135 | 1148 | std::vector<DexAnnotation*>& annolist) { |
1136 | 1149 | int annocnt = 0; |
1137 | 1150 | uint32_t mentry_offset = m_offset; |
1138 | | - std::map<std::vector<uint8_t>, uint32_t> annotation_byte_offsets; |
| 1151 | + UnorderedMap<std::vector<uint8_t>, uint32_t, VectorHash<uint8_t>> |
| 1152 | + annotation_byte_offsets; |
1139 | 1153 | for (auto* anno : annolist) { |
1140 | 1154 | if (annomap.count(anno) != 0u) { |
1141 | 1155 | continue; |
@@ -1167,7 +1181,8 @@ void DexOutput::unique_asets(annomap_t& annomap, |
1167 | 1181 | std::vector<DexAnnotationSet*>& asetlist) { |
1168 | 1182 | int asetcnt = 0; |
1169 | 1183 | uint32_t mentry_offset = align(m_offset); |
1170 | | - std::map<std::vector<uint32_t>, uint32_t> aset_offsets; |
| 1184 | + UnorderedMap<std::vector<uint32_t>, uint32_t, VectorHash<uint32_t>> |
| 1185 | + aset_offsets; |
1171 | 1186 | for (auto* aset : asetlist) { |
1172 | 1187 | if (asetmap.count(aset) != 0u) { |
1173 | 1188 | continue; |
@@ -1199,7 +1214,8 @@ void DexOutput::unique_xrefs(asetmap_t& asetmap, |
1199 | 1214 | std::vector<ParamAnnotations*>& xreflist) { |
1200 | 1215 | int xrefcnt = 0; |
1201 | 1216 | uint32_t mentry_offset = align(m_offset); |
1202 | | - std::map<std::vector<uint32_t>, uint32_t> xref_offsets; |
| 1217 | + UnorderedMap<std::vector<uint32_t>, uint32_t, VectorHash<uint32_t>> |
| 1218 | + xref_offsets; |
1203 | 1219 | for (auto* xref : xreflist) { |
1204 | 1220 | if (xrefmap.count(xref) != 0u) { |
1205 | 1221 | continue; |
@@ -1238,7 +1254,8 @@ void DexOutput::unique_adirs(asetmap_t& asetmap, |
1238 | 1254 | std::vector<DexAnnotationDirectory*>& adirlist) { |
1239 | 1255 | int adircnt = 0; |
1240 | 1256 | uint32_t mentry_offset = align(m_offset); |
1241 | | - std::map<std::vector<uint32_t>, uint32_t> adir_offsets; |
| 1257 | + UnorderedMap<std::vector<uint32_t>, uint32_t, VectorHash<uint32_t>> |
| 1258 | + adir_offsets; |
1242 | 1259 | for (auto* adir : adirlist) { |
1243 | 1260 | if (adirmap.count(adir) != 0u) { |
1244 | 1261 | continue; |
|
0 commit comments