# better string literal caching implementation · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/f8fe517d126d582e37ab4537fe9fd42f0531f44b)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: f8fe517d126d582e37ab4537fe9fd42f0531f44b

Requested commit: f8fe517d126d582e37ab4537fe9fd42f0531f44b

Commit: f8fe517d126d582e37ab4537fe9fd42f0531f44b

Tree: 040baa17d21eb30b1dc7d2a4ef470fe7aea08e85

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
better string literal caching implementation

We were caching the ConstExprValue of string literals,
which works if you can never modify ConstExprValues.
This premise is broken with `comptime var ...`.

So I implemented an optimization in ConstExprValue
arrays, where it stores a `Buf *` directly rather
than an array of ConstExprValues for the elements,
and then similar to array of undefined, it is
expanded into the canonical form when necessary.
However many operations can happen directly on the
`Buf *`, which is faster.

Furthermore, before a ConstExprValue array is expanded
into canonical form, it removes itself from the string
literal cache. This fixes the issue, because before an
array element is modified it would have to be expanded.

closes #1076

```

## Parents

- [492821781dc34659f694577aacbc853c8839406f](https://git.cafe/gitcafe/zig/commit/492821781dc34659f694577aacbc853c8839406f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/f8fe517d126d582e37ab4537fe9fd42f0531f44b?format=markdown)
