| 2234 | |
| 2235 | |
| 2236 | void Resources::add(const Resource_& that) |
| 2237 | { |
| 2238 | if (that.isEmpty()) { |
| 2239 | return; |
| 2240 | } |
| 2241 | |
| 2242 | bool found = false; |
| 2243 | foreach ( |
| 2244 | Resource_Unsafe& resource_, |
| 2245 | resourcesNoMutationWithoutExclusiveOwnership) { |
| 2246 | if (internal::addable(resource_->resource, that.resource)) { |
| 2247 | // Copy-on-write (if more than 1 reference). |
| 2248 | if (resource_.use_count() > 1) { |
| 2249 | resource_ = make_shared<Resource_>(*resource_); |
| 2250 | } |
| 2251 | |
| 2252 | *resource_ += that; |
| 2253 | found = true; |
| 2254 | break; |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | // Cannot be combined with any existing Resource object. |
| 2259 | if (!found) { |
| 2260 | resourcesNoMutationWithoutExclusiveOwnership.push_back( |
| 2261 | make_shared<Resource_>(that)); |
| 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | void Resources::add(Resource_&& that) |
no test coverage detected