| 35 | } |
| 36 | |
| 37 | foreach (const WeightInfo& weightInfo, weightInfos) { |
| 38 | bool hasStored = false; |
| 39 | for (int i = 0; i < registry->weights().size(); ++i) { |
| 40 | Registry::Weight* weight = registry->mutable_weights(i); |
| 41 | |
| 42 | if (weight->info().role() != weightInfo.role()) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | hasStored = true; |
| 47 | |
| 48 | // If there is already weight stored for the specified role |
| 49 | // and also its value is changed, update the entry. |
| 50 | if (weight->info().weight() != weightInfo.weight()) { |
| 51 | weight->mutable_info()->CopyFrom(weightInfo); |
| 52 | mutated = true; |
| 53 | } |
| 54 | |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | // If there is no weight yet for this role in registry, |
| 59 | // create a new entry. |
| 60 | if (!hasStored) { |
| 61 | registry->add_weights()->mutable_info()->CopyFrom(weightInfo); |
| 62 | mutated = true; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return mutated; |
| 67 | } |