Indexing for fluid chaining
| 538 | |
| 539 | // Indexing for fluid chaining |
| 540 | json operator[](size_t idx) FL_NOEXCEPT { |
| 541 | if (!mValue) { |
| 542 | mValue = fl::make_shared<json_value>(json_array{}); |
| 543 | } |
| 544 | // If we're indexing into a specialized array, convert it to regular json_array first |
| 545 | if (mValue->data.is<fl::vector<i16>>() || |
| 546 | mValue->data.is<fl::vector<u8>>() || |
| 547 | mValue->data.is<fl::vector<float>>()) { |
| 548 | // Convert to regular json_array (needs a copy/conversion) |
| 549 | auto arr = mValue->clone_array(); |
| 550 | if (arr) { |
| 551 | mValue = fl::make_shared<json_value>(fl::move(*arr)); |
| 552 | } |
| 553 | } |
| 554 | // Get pointer directly to avoid copying - fixes silent mutation bug |
| 555 | auto arrPtr = mValue->as_array(); |
| 556 | if (arrPtr) { |
| 557 | // Ensure the array is large enough |
| 558 | if (idx >= arrPtr->size()) { |
| 559 | for (size_t i = arrPtr->size(); i <= idx; i++) { |
| 560 | arrPtr->push_back(fl::make_shared<json_value>(nullptr)); |
| 561 | } |
| 562 | } |
| 563 | return json((*arrPtr)[idx]); |
| 564 | } |
| 565 | return json(nullptr); |
| 566 | } |
| 567 | |
| 568 | const json operator[](size_t idx) const FL_NOEXCEPT { |
| 569 | if (!mValue) { |