Replace bitset with stdlib math/big

Sync changes in runc https://github.com/opencontainers/runc/pull/3219
This commit is contained in:
Shengjing Zhu
2022-09-15 00:09:35 +08:00
committed by Shengjing Zhu
parent 175282956a
commit 7cc16b41df
5 changed files with 8 additions and 28 deletions
-7
View File
@@ -1896,10 +1896,3 @@ go_repository(
sum = "h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=",
version = "v1.2.0",
)
go_repository(
name = "com_github_bits_and_blooms_bitset",
importpath = "github.com/bits-and-blooms/bitset",
sum = "h1:M+/hrU9xlMp7t4TyTDQW97d3tRPVuKFC6zBEK16QnXY=",
version = "v1.2.1",
)
-1
View File
@@ -5,7 +5,6 @@ go 1.17
require (
github.com/BurntSushi/toml v0.3.1
github.com/bazelbuild/rules_go v0.30.0
github.com/bits-and-blooms/bitset v1.2.0
github.com/cenkalti/backoff v1.1.1-0.20190506075156-2146c9339422
github.com/containerd/cgroups v1.0.1
github.com/containerd/console v1.0.1
-2
View File
@@ -61,8 +61,6 @@ github.com/bazelbuild/rules_go v0.30.0 h1:kX4jVcstqrsRqKPJSn2mq2o+TI21edRzEJSrEO
github.com/bazelbuild/rules_go v0.30.0/go.mod h1:MC23Dc/wkXEyk3Wpq6lCqz0ZAYOZDw2DR5y3N1q2i7M=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/cenkalti/backoff v1.1.1-0.20190506075156-2146c9339422 h1:8eZxmY1yvxGHzdzTEhI09npjMVGzNAdrqzruTX6jcK4=
github.com/cenkalti/backoff v1.1.1-0.20190506075156-2146c9339422/go.mod h1:b6Nc7NRH5C4aCISLry0tLnTjcuTEvoiqcWDdsU0sOGM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
-1
View File
@@ -13,7 +13,6 @@ go_library(
deps = [
"//pkg/cleanup",
"//pkg/log",
"@com_github_bits_and_blooms_bitset//:go_default_library",
"@com_github_cenkalti_backoff//:go_default_library",
"@com_github_coreos_go_systemd_v22//dbus:go_default_library",
"@com_github_godbus_dbus_v5//:go_default_library",
+8 -17
View File
@@ -20,18 +20,17 @@ import (
"bufio"
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"io/ioutil"
"math"
"math/big"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/bits-and-blooms/bitset"
"github.com/cenkalti/backoff"
"github.com/coreos/go-systemd/v22/dbus"
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -834,7 +833,8 @@ func parseUint(s string, base, bitSize int) (uint64, error) {
// AllowedCPUs/AllowedMemoryNodes unit property value).
// Copied from runc.
func RangeToBits(str string) ([]byte, error) {
bits := &bitset.BitSet{}
bits := &big.Int{}
for _, r := range strings.Split(str, ",") {
// allow extra spaces around
r = strings.TrimSpace(r)
@@ -855,31 +855,22 @@ func RangeToBits(str string) ([]byte, error) {
if start > end {
return nil, errors.New("invalid range: " + r)
}
for i := uint(start); i <= uint(end); i++ {
bits.Set(i)
for i := start; i <= end; i++ {
bits.SetBit(bits, int(i), 1)
}
} else {
val, err := strconv.ParseUint(ranges[0], 10, 32)
if err != nil {
return nil, err
}
bits.Set(uint(val))
bits.SetBit(bits, int(val), 1)
}
}
val := bits.Bytes()
if len(val) == 0 {
ret := bits.Bytes()
if len(ret) == 0 {
// do not allow empty values
return nil, errors.New("empty value")
}
ret := make([]byte, len(val)*8)
for i := range val {
// bitset uses BigEndian internally
binary.BigEndian.PutUint64(ret[i*8:], val[len(val)-1-i])
}
// remove upper all-zero bytes
for ret[0] == 0 {
ret = ret[1:]
}
return ret, nil
}