| 930 | } |
| 931 | |
| 932 | void merge(const CountMemBlock &other) { |
| 933 | // if LHS has x more non-locals than RHS, then it gets to keep the first |
| 934 | // x cached accessed pointers, as for sure we have accessed all common |
| 935 | // pointers plus x extra pointers if we go through the LHS path |
| 936 | unsigned delta = num_nonlocals - other.num_nonlocals; |
| 937 | bool lhs_larger = num_nonlocals >= other.num_nonlocals; |
| 938 | if (!lhs_larger) { |
| 939 | num_nonlocals = other.num_nonlocals; |
| 940 | delta = -delta; |
| 941 | } |
| 942 | |
| 943 | for (auto I = nonlocal_cache.begin(); I != nonlocal_cache.end(); ) { |
| 944 | if (other.nonlocal_cache.count(*I)) { |
| 945 | ++I; |
| 946 | } else if (delta > 0) { |
| 947 | ++I; |
| 948 | --delta; |
| 949 | } else { |
| 950 | I = nonlocal_cache.erase(I); |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | for (auto &e : other.nonlocal_cache) { |
| 955 | if (delta > 0 && nonlocal_cache.emplace(e).second) { |
| 956 | --delta; |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | }; |
| 961 | } |
| 962 | |