Returns the minimum address used by the given Value (transitively). If that minimum address comes before _baseCutoff, immediately returns null.
| 443 | // Returns the minimum address used by the given Value (transitively). |
| 444 | // If that minimum address comes before _baseCutoff, immediately returns null. |
| 445 | const Value* Encoder::minUsed(const Value *value) { |
| 446 | if (value < _baseCutoff) |
| 447 | return nullptr; |
| 448 | switch (value->type()) { |
| 449 | case kArray: { |
| 450 | const Value *minVal = value; |
| 451 | for (Array::iterator i((const Array*)value); i; ++i) { |
| 452 | minVal = std::min(minVal, minUsed(i.value())); |
| 453 | if (minVal == nullptr) |
| 454 | break; |
| 455 | } |
| 456 | return minVal; |
| 457 | } |
| 458 | case kDict: { |
| 459 | const Value *minVal = value; |
| 460 | for (Dict::iterator i((const Dict*)value, false); i; ++i) { |
| 461 | minVal = std::min(minVal, minUsed(i.key())); |
| 462 | minVal = std::min(minVal, minUsed(i.value())); |
| 463 | if (minVal == nullptr) |
| 464 | break; |
| 465 | } |
| 466 | return minVal; |
| 467 | } |
| 468 | default: |
| 469 | return value; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | |
| 474 | void Encoder::writeValue(const Value *value, |