# Improve and remove duplicate doNotOptimizeAway\(\) implementations \(\#13790\) · gitcafe/zig

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

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

Visibility: public

Requested revision: c49e4d534fb8e8ec994a8ffbc62eae8ef1e4e819

Requested commit: c49e4d534fb8e8ec994a8ffbc62eae8ef1e4e819

Commit: c49e4d534fb8e8ec994a8ffbc62eae8ef1e4e819

Tree: 0194dab2137336a88964fc781f62ea3aa8f0bef0

Author: Frank Denis

Committer: GitHub

## Message

```
Improve and remove duplicate doNotOptimizeAway() implementations (#13790)

* Improve and remove duplicate doNotOptimizeAway() implementations

We currently have two doNotOptimizeAway() implementations, one in
std.math and the other one in std.mem.

Maybe we should deprecate one. In the meantime, the std.math one
now just calls the std.mem one.

In a comptime environment, just ignore the value. Previously,
std.mem.doNotOptimizeAway() did not work at comptime.

If the value fits in a CPU register, just tell the compiler we
need that value to be computed, without clobbering anything else.

Only clobber all possibly escaped memory on pointers or large arrays.

Add tests by the way since we didn't had any (we had, but only
indirect ones).
```

## Parents

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

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