# gpui: Improve \`PlatformAtlas::get_or_insert_with\` \(\#64331\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/0ef92145ff87aab5f19f6b44c9c55a486f4f064f)

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

Visibility: public

Requested revision: 0ef92145ff87aab5f19f6b44c9c55a486f4f064f

Requested commit: 0ef92145ff87aab5f19f6b44c9c55a486f4f064f

Commit: 0ef92145ff87aab5f19f6b44c9c55a486f4f064f

Tree: 821bf5361a03905c6cb659805566f2285362ad02

Author: Finn Evers

Committer: GitHub

## Message

```
gpui: Improve `PlatformAtlas::get_or_insert_with` (#64331)

Stumbled across this during a recent review:

At all of the call sites in prod code, we would clone, then into, then
pass by ref, and then immediately clone again in `get_or_insert_with`
when the texture was not found.

Instead, changed the API to now take an owned `AtlasKey` to make better
use of the cloning.

As a second step, went ahead and added a generic `AtlasState`, as I
noticed all atlases shared some similar logic around keeping track of
the tiles. With this restructing, we reuse some code across different
backends, but more importantly, get rid of an additional hashmap lookup
by instead using the `Entry` API.

Release Notes:

- N/A
- [GPUI] N/A
```

## Parents

- [31971937b5c44dc837efb0e172f951264a10c7fd](https://git.cafe/gitcafe/zed/commit/31971937b5c44dc837efb0e172f951264a10c7fd?format=markdown)

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