| 2201 | |
| 2202 | |
| 2203 | void Resources::add(const Resource_& that) |
| 2204 | { |
| 2205 | if (that.isEmpty()) { |
| 2206 | return; |
| 2207 | } |
| 2208 | |
| 2209 | bool found = false; |
| 2210 | foreach ( |
| 2211 | Resource_Unsafe& resource_, |
| 2212 | resourcesNoMutationWithoutExclusiveOwnership) { |
| 2213 | if (internal::addable(resource_->resource, that.resource)) { |
| 2214 | // Copy-on-write (if more than 1 reference). |
| 2215 | if (resource_.use_count() > 1) { |
| 2216 | resource_ = make_shared<Resource_>(*resource_); |
| 2217 | } |
| 2218 | |
| 2219 | *resource_ += that; |
| 2220 | found = true; |
| 2221 | break; |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | // Cannot be combined with any existing Resource object. |
| 2226 | if (!found) { |
| 2227 | resourcesNoMutationWithoutExclusiveOwnership.push_back( |
| 2228 | make_shared<Resource_>(that)); |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | |
| 2233 | void Resources::add(Resource_&& that) |