EngineHub / EngineHub/CommandHelper

array()'s cached string representation can go out of sync

Đang mở
#1,242 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Java
Star
128
Fork
70
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

The cache used for `array()` its string representation runs out of sync with the actual array data in the following examples:
```
@a = array(1);
@b = array(@a);
@c = array(@a);
msg(@b); // Caching happens here, result is `{{1}}`.
msg(@c); // Caching happens here, result is `{{1}}`.
@a[0] = 2; // The array marks its last parent's cache as dirty, but not its other parent.
msg(@b); // Return cached result `{{1}}`, which is wrong at this point.
msg(@c); // Re-cache, returning the actual result `{{2}}`.
```

```
@a = mutable_primitive('test');
@b = array(@a);
msg(@b); // Caching happens here, result is `{test}`.
@a[] = 'newValue';
msg(@b); // Return cached result `{test}`, which is wrong at this point.
```

For arrays, marking all parents as dirty can be a solution (whereas it currently only marks the last parent as dirty). For mutable primitives, or user objects, the solution is not trivial. In my opinion, we could go without caching array string representations as soon as #1225 is merged and a similar solution for not sconcatting all code together is implemented in non-strict mode. I believe that arrays are not often used as their string representation, and if they are, they are rarely used twice (in which case the cache would improve performance).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.