Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
go source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
ARM gc (tip)
ARM gc 1.14
ARM gc 1.15
ARM gc 1.16
ARM gc 1.17
ARM gc 1.18
ARM gc 1.19
ARM gc 1.20
ARM gc 1.21
ARM gc 1.22.1
ARM gc 1.23.2
ARM gccgo 12.2.0
ARM gccgo 12.3.0
ARM gccgo 12.4.0
ARM gccgo 13.1.0
ARM gccgo 13.2.0
ARM gccgo 13.3.0
ARM gccgo 14.1.0
ARM gccgo 14.2.0
ARM64 gc (tip)
ARM64 gc 1.14
ARM64 gc 1.15
ARM64 gc 1.16
ARM64 gc 1.17
ARM64 gc 1.18
ARM64 gc 1.19
ARM64 gc 1.20
ARM64 gc 1.21
ARM64 gc 1.22.1
ARM64 gc 1.23.2
ARM64 gccgo 12.2.0
ARM64 gccgo 12.3.0
ARM64 gccgo 12.4.0
ARM64 gccgo 13.1.0
ARM64 gccgo 13.2.0
ARM64 gccgo 13.3.0
ARM64 gccgo 14.1.0
ARM64 gccgo 14.2.0
MIPS gc (tip)
MIPS gc 1.14
MIPS gc 1.15
MIPS gc 1.16
MIPS gc 1.17
MIPS gc 1.18
MIPS gc 1.19
MIPS gc 1.20
MIPS gc 1.21
MIPS gc 1.22.1
MIPS gc 1.23.2
MIPS gccgo 12.2.0
MIPS gccgo 12.3.0
MIPS gccgo 12.4.0
MIPS gccgo 13.1.0
MIPS gccgo 13.2.0
MIPS gccgo 13.3.0
MIPS gccgo 14.1.0
MIPS gccgo 14.2.0
MIPS64 gc (tip)
MIPS64 gc 1.14
MIPS64 gc 1.15
MIPS64 gc 1.16
MIPS64 gc 1.17
MIPS64 gc 1.18
MIPS64 gc 1.19
MIPS64 gc 1.20
MIPS64 gc 1.21
MIPS64 gc 1.22.1
MIPS64 gc 1.23.2
MIPS64 gccgo 12.2.0
MIPS64 gccgo 12.3.0
MIPS64 gccgo 12.4.0
MIPS64 gccgo 13.1.0
MIPS64 gccgo 13.2.0
MIPS64 gccgo 13.3.0
MIPS64 gccgo 14.1.0
MIPS64 gccgo 14.2.0
MIPS64EL gccgo 12.2.0
MIPS64EL gccgo 12.3.0
MIPS64EL gccgo 12.4.0
MIPS64EL gccgo 13.1.0
MIPS64EL gccgo 13.2.0
MIPS64EL gccgo 13.3.0
MIPS64EL gccgo 14.1.0
MIPS64EL gccgo 14.2.0
MIPS64LE gc (tip)
MIPS64LE gc 1.14
MIPS64LE gc 1.15
MIPS64LE gc 1.16
MIPS64LE gc 1.17
MIPS64LE gc 1.18
MIPS64LE gc 1.19
MIPS64LE gc 1.20
MIPS64LE gc 1.21
MIPS64LE gc 1.22.1
MIPS64LE gc 1.23.2
MIPSEL gccgo 12.2.0
MIPSEL gccgo 12.3.0
MIPSEL gccgo 12.4.0
MIPSEL gccgo 13.1.0
MIPSEL gccgo 13.2.0
MIPSEL gccgo 13.3.0
MIPSEL gccgo 14.1.0
MIPSEL gccgo 14.2.0
MIPSLE gc (tip)
MIPSLE gc 1.14
MIPSLE gc 1.15
MIPSLE gc 1.16
MIPSLE gc 1.17
MIPSLE gc 1.18
MIPSLE gc 1.19
MIPSLE gc 1.20
MIPSLE gc 1.21
MIPSLE gc 1.22.1
MIPSLE gc 1.23.2
POWER gccgo 12.2.0
POWER gccgo 12.3.0
POWER gccgo 12.4.0
POWER gccgo 13.1.0
POWER gccgo 13.2.0
POWER gccgo 13.3.0
POWER gccgo 14.1.0
POWER gccgo 14.2.0
POWER64 gc (tip)
POWER64 gc 1.14
POWER64 gc 1.15
POWER64 gc 1.16
POWER64 gc 1.17
POWER64 gc 1.18
POWER64 gc 1.19
POWER64 gc 1.20
POWER64 gc 1.21
POWER64 gc 1.22.1
POWER64 gc 1.23.2
POWER64 gccgo 12.2.0
POWER64 gccgo 12.3.0
POWER64 gccgo 12.4.0
POWER64 gccgo 13.1.0
POWER64 gccgo 13.2.0
POWER64 gccgo 13.3.0
POWER64 gccgo 14.1.0
POWER64 gccgo 14.2.0
POWER64 gccgo AT12.0
POWER64 gccgo AT13.0
POWER64 gccgo trunk
POWER64LE gc (tip)
POWER64LE gc 1.14
POWER64LE gc 1.15
POWER64LE gc 1.16
POWER64LE gc 1.17
POWER64LE gc 1.18
POWER64LE gc 1.19
POWER64LE gc 1.20
POWER64LE gc 1.21
POWER64LE gc 1.22.1
POWER64LE gc 1.23.2
POWER64LE gccgo 12.2.0
POWER64LE gccgo 12.3.0
POWER64LE gccgo 12.4.0
POWER64LE gccgo 13.1.0
POWER64LE gccgo 13.2.0
POWER64LE gccgo 13.3.0
POWER64LE gccgo 14.1.0
POWER64LE gccgo 14.2.0
POWER64LE gccgo AT12.0
POWER64LE gccgo AT13.0
POWER64LE gccgo trunk
RISC-V 64 gc (tip)
RISC-V 64 gc 1.14
RISC-V 64 gc 1.15
RISC-V 64 gc 1.16
RISC-V 64 gc 1.17
RISC-V 64 gc 1.18
RISC-V 64 gc 1.19
RISC-V 64 gc 1.20
RISC-V 64 gc 1.21
RISC-V 64 gc 1.22.1
RISC-V 64 gc 1.23.2
RISC-V 64 gccgo 12.2.0
RISC-V 64 gccgo 12.3.0
RISC-V 64 gccgo 12.4.0
RISC-V 64 gccgo 13.1.0
RISC-V 64 gccgo 13.2.0
RISC-V 64 gccgo 13.3.0
RISC-V 64 gccgo 14.1.0
RISC-V 64 gccgo 14.2.0
S390X gc (tip)
S390X gc 1.14
S390X gc 1.15
S390X gc 1.16
S390X gc 1.17
S390X gc 1.18
S390X gc 1.19
S390X gc 1.20
S390X gc 1.21
S390X gc 1.22.1
S390X gc 1.23.2
S390X gccgo 12.2.0
S390X gccgo 12.3.0
S390X gccgo 12.4.0
S390X gccgo 13.1.0
S390X gccgo 13.2.0
S390X gccgo 13.3.0
S390X gccgo 14.1.0
S390X gccgo 14.2.0
SPARC gccgo 12.2.0
SPARC gccgo 12.3.0
SPARC gccgo 12.4.0
SPARC gccgo 13.1.0
SPARC gccgo 13.2.0
SPARC gccgo 13.3.0
SPARC gccgo 14.1.0
SPARC gccgo 14.2.0
SPARC64 gccgo 12.2.0
SPARC64 gccgo 12.3.0
SPARC64 gccgo 12.4.0
SPARC64 gccgo 13.1.0
SPARC64 gccgo 13.2.0
SPARC64 gccgo 13.3.0
SPARC64 gccgo 14.1.0
SPARC64 gccgo 14.2.0
WASM gc (tip)
WASM gc 1.14
WASM gc 1.15
WASM gc 1.16
WASM gc 1.17
WASM gc 1.18
WASM gc 1.19
WASM gc 1.20
WASM gc 1.21
WASM gc 1.22.1
WASM gc 1.23.2
x86 gc (tip)
x86 gc 1.14
x86 gc 1.15
x86 gc 1.16
x86 gc 1.17
x86 gc 1.18
x86 gc 1.19
x86 gc 1.20
x86 gc 1.21
x86 gc 1.22.1
x86 gc 1.23.2
x86 gccgo 10.2.0
x86 gccgo 10.5.0
x86 gccgo 11.1.0
x86 gccgo 11.2.0
x86 gccgo 11.3.0
x86 gccgo 11.4.0
x86 gccgo 12.1.0
x86 gccgo 12.2.0
x86 gccgo 12.3.0
x86 gccgo 12.4.0
x86 gccgo 13.1
x86 gccgo 13.2
x86 gccgo 13.3
x86 gccgo 14.1
x86 gccgo 14.2
x86 gccgo 4.9.4
x86 gccgo 6.3.0
x86 gccgo 7.2.0
x86 gccgo 8.3.0
x86 gccgo 9.3.0
x86 gccgo 9.5.0
x86-64 gc (tip)
x86-64 gc 1.10
x86-64 gc 1.10.1
x86-64 gc 1.11
x86-64 gc 1.12
x86-64 gc 1.13
x86-64 gc 1.14
x86-64 gc 1.15
x86-64 gc 1.16
x86-64 gc 1.17
x86-64 gc 1.18
x86-64 gc 1.19
x86-64 gc 1.20
x86-64 gc 1.21
x86-64 gc 1.22.1
x86-64 gc 1.23.2
x86-64 gc 1.4.1
x86-64 gc 1.7.2
x86-64 gc 1.8.5
x86-64 gc 1.8.7
x86-64 gc 1.9.2
x86-64 gc 1.9.4
Options
Source code
package main import "fmt" type kv struct { key []byte value []byte } type sliceMap []kv func (sm *sliceMap) Add(k, v []byte) { kvs := *sm if cap(kvs) > len(kvs) { kvs = kvs[:len(kvs)+1] } else { kvs = append(kvs, kv{}) } kv := &kvs[len(kvs)-1] kv.key = append(kv.key[:0], k...) kv.value = append(kv.value[:0], v...) *sm = kvs } func main() { sm := sliceMap{} sm.Add([]byte("foo"), []byte("bar")) fmt.Println(sm) }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree