---
title: "separate-byte-string-map-key"
description: "Detect allocated byte-to-string temporaries used only for map lookups."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# separate-byte-string-map-key

**Default severity:** `warning`

The compiler can perform `items[string(bytes)]` without copying the byte slice
because the temporary string cannot escape the lookup. Assigning
`string(bytes)` to a variable first prevents that optimization and allocates
when the variable is used only as a map key.

The check stays silent when the string variable has any non-lookup use.

## Bad

```go
key := string(keyBytes); value := items[key]
```

## Good

```go
value := items[string(keyBytes)]
```

Source: https://strider.gempir.com/analyzers/separate-byte-string-map-key/index.mdx
