Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ '1.22' ]
steps:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: false
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.1
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
name: Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ '1.18', '1.19', '1.20', '1.21', '1.22', '1.23' ]
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Test
run: make tests

- name: Test coverage
run: make code-coverage

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
flag-name: Go-${{ matrix.go }}
continue-on-error: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/coverage.out
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 go-slice
Copyright (c) 2024 Bartlomiej Krukowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests:
go test -race -count=1 -coverprofile=coverage.out ./...

code-coverage:
go tool cover -func=coverage.out
36 changes: 36 additions & 0 deletions benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package slice_test

import (
"testing"

"github.com/go-slice/slice"
)

func BenchmarkSlice_Unshift(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
s := slice.FromRaw(make([]int, 5, 10))
s.Unshift(1, 2)
}
}

func BenchmarkSlice_Unshift_native(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
s := make([]int, 5, 10)
s = append(append([]int(nil), 1, 2), s...) //nolint:ineffassign,staticcheck
}
}

func BenchmarkSlice_Filter(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
s := slice.FromRaw([]int{1, 2, 3, 4, 5})
s.Filter(func(_ int, val int) bool {
return val%2 == 0
})
}
}
9 changes: 9 additions & 0 deletions clear_polyfill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package slice

func clear[T any, S ~[]T](in S) {
var x T

for i := 0; i < len(in); i++ {
in[i] = x
}
}
Loading
Loading