vendor: update 'golang.org/x/time/rate' with context

Go just updated its import path c06e80d930

For https://github.com/coreos/etcd/issues/6174.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
release-3.2
Gyu-Ho Lee 2017-04-20 11:18:34 -07:00
parent 633a4e6b52
commit da1bba8f39
6 changed files with 46 additions and 43 deletions

View File

@ -33,17 +33,9 @@ const (
// streamSafe implements the policy of when a CGJ should be inserted. // streamSafe implements the policy of when a CGJ should be inserted.
type streamSafe uint8 type streamSafe uint8
// mkStreamSafe is a shorthand for declaring a streamSafe var and calling // first inserts the first rune of a segment. It is a faster version of next if
// first on it. // it is known p represents the first rune in a segment.
func mkStreamSafe(p Properties) streamSafe {
return streamSafe(p.nTrailingNonStarters())
}
// first inserts the first rune of a segment.
func (ss *streamSafe) first(p Properties) { func (ss *streamSafe) first(p Properties) {
if *ss != 0 {
panic("!= 0")
}
*ss = streamSafe(p.nTrailingNonStarters()) *ss = streamSafe(p.nTrailingNonStarters())
} }
@ -66,7 +58,7 @@ func (ss *streamSafe) next(p Properties) ssState {
// be a non-starter. Note that it always hold that if nLead > 0 then // be a non-starter. Note that it always hold that if nLead > 0 then
// nLead == nTrail. // nLead == nTrail.
if n == 0 { if n == 0 {
*ss = 0 *ss = streamSafe(p.nTrailingNonStarters())
return ssStarter return ssStarter
} }
return ssSuccess return ssSuccess
@ -142,7 +134,6 @@ func (rb *reorderBuffer) setFlusher(out []byte, f func(*reorderBuffer) bool) {
func (rb *reorderBuffer) reset() { func (rb *reorderBuffer) reset() {
rb.nrune = 0 rb.nrune = 0
rb.nbyte = 0 rb.nbyte = 0
rb.ss = 0
} }
func (rb *reorderBuffer) doFlush() bool { func (rb *reorderBuffer) doFlush() bool {
@ -257,6 +248,9 @@ func (rb *reorderBuffer) insertUnsafe(src input, i int, info Properties) {
// It flushes the buffer on each new segment start. // It flushes the buffer on each new segment start.
func (rb *reorderBuffer) insertDecomposed(dcomp []byte) insertErr { func (rb *reorderBuffer) insertDecomposed(dcomp []byte) insertErr {
rb.tmpBytes.setBytes(dcomp) rb.tmpBytes.setBytes(dcomp)
// As the streamSafe accounting already handles the counting for modifiers,
// we don't have to call next. However, we do need to keep the accounting
// intact when flushing the buffer.
for i := 0; i < len(dcomp); { for i := 0; i < len(dcomp); {
info := rb.f.info(rb.tmpBytes, i) info := rb.f.info(rb.tmpBytes, i)
if info.BoundaryBefore() && rb.nrune > 0 && !rb.doFlush() { if info.BoundaryBefore() && rb.nrune > 0 && !rb.doFlush() {

View File

@ -41,6 +41,7 @@ func (i *Iter) Init(f Form, src []byte) {
i.next = i.rb.f.nextMain i.next = i.rb.f.nextMain
i.asciiF = nextASCIIBytes i.asciiF = nextASCIIBytes
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
i.rb.ss.first(i.info)
} }
// InitString initializes i to iterate over src after normalizing it to Form f. // InitString initializes i to iterate over src after normalizing it to Form f.
@ -56,11 +57,12 @@ func (i *Iter) InitString(f Form, src string) {
i.next = i.rb.f.nextMain i.next = i.rb.f.nextMain
i.asciiF = nextASCIIString i.asciiF = nextASCIIString
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
i.rb.ss.first(i.info)
} }
// Seek sets the segment to be returned by the next call to Next to start // Seek sets the segment to be returned by the next call to Next to start
// at position p. It is the responsibility of the caller to set p to the // at position p. It is the responsibility of the caller to set p to the
// start of a UTF8 rune. // start of a segment.
func (i *Iter) Seek(offset int64, whence int) (int64, error) { func (i *Iter) Seek(offset int64, whence int) (int64, error) {
var abs int64 var abs int64
switch whence { switch whence {
@ -84,6 +86,7 @@ func (i *Iter) Seek(offset int64, whence int) (int64, error) {
i.multiSeg = nil i.multiSeg = nil
i.next = i.rb.f.nextMain i.next = i.rb.f.nextMain
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
i.rb.ss.first(i.info)
return abs, nil return abs, nil
} }
@ -161,6 +164,7 @@ func nextHangul(i *Iter) []byte {
if next >= i.rb.nsrc { if next >= i.rb.nsrc {
i.setDone() i.setDone()
} else if i.rb.src.hangul(next) == 0 { } else if i.rb.src.hangul(next) == 0 {
i.rb.ss.next(i.info)
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
i.next = i.rb.f.nextMain i.next = i.rb.f.nextMain
return i.next(i) return i.next(i)
@ -204,12 +208,10 @@ func nextMultiNorm(i *Iter) []byte {
if info.BoundaryBefore() { if info.BoundaryBefore() {
i.rb.compose() i.rb.compose()
seg := i.buf[:i.rb.flushCopy(i.buf[:])] seg := i.buf[:i.rb.flushCopy(i.buf[:])]
i.rb.ss.first(info)
i.rb.insertUnsafe(input{bytes: d}, j, info) i.rb.insertUnsafe(input{bytes: d}, j, info)
i.multiSeg = d[j+int(info.size):] i.multiSeg = d[j+int(info.size):]
return seg return seg
} }
i.rb.ss.next(info)
i.rb.insertUnsafe(input{bytes: d}, j, info) i.rb.insertUnsafe(input{bytes: d}, j, info)
j += int(info.size) j += int(info.size)
} }
@ -222,9 +224,9 @@ func nextMultiNorm(i *Iter) []byte {
func nextDecomposed(i *Iter) (next []byte) { func nextDecomposed(i *Iter) (next []byte) {
outp := 0 outp := 0
inCopyStart, outCopyStart := i.p, 0 inCopyStart, outCopyStart := i.p, 0
ss := mkStreamSafe(i.info)
for { for {
if sz := int(i.info.size); sz <= 1 { if sz := int(i.info.size); sz <= 1 {
i.rb.ss = 0
p := i.p p := i.p
i.p++ // ASCII or illegal byte. Either way, advance by 1. i.p++ // ASCII or illegal byte. Either way, advance by 1.
if i.p >= i.rb.nsrc { if i.p >= i.rb.nsrc {
@ -243,6 +245,8 @@ func nextDecomposed(i *Iter) (next []byte) {
p := outp + len(d) p := outp + len(d)
if outp > 0 { if outp > 0 {
i.rb.src.copySlice(i.buf[outCopyStart:], inCopyStart, i.p) i.rb.src.copySlice(i.buf[outCopyStart:], inCopyStart, i.p)
// TODO: this condition should not be possible, but we leave it
// in for defensive purposes.
if p > len(i.buf) { if p > len(i.buf) {
return i.buf[:outp] return i.buf[:outp]
} }
@ -266,7 +270,7 @@ func nextDecomposed(i *Iter) (next []byte) {
} else { } else {
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
} }
switch ss.next(i.info) { switch i.rb.ss.next(i.info) {
case ssOverflow: case ssOverflow:
i.next = nextCGJDecompose i.next = nextCGJDecompose
fallthrough fallthrough
@ -309,7 +313,7 @@ func nextDecomposed(i *Iter) (next []byte) {
} }
prevCC := i.info.tccc prevCC := i.info.tccc
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
if v := ss.next(i.info); v == ssStarter { if v := i.rb.ss.next(i.info); v == ssStarter {
break break
} else if v == ssOverflow { } else if v == ssOverflow {
i.next = nextCGJDecompose i.next = nextCGJDecompose
@ -335,10 +339,6 @@ doNorm:
func doNormDecomposed(i *Iter) []byte { func doNormDecomposed(i *Iter) []byte {
for { for {
if s := i.rb.ss.next(i.info); s == ssOverflow {
i.next = nextCGJDecompose
break
}
i.rb.insertUnsafe(i.rb.src, i.p, i.info) i.rb.insertUnsafe(i.rb.src, i.p, i.info)
if i.p += int(i.info.size); i.p >= i.rb.nsrc { if i.p += int(i.info.size); i.p >= i.rb.nsrc {
i.setDone() i.setDone()
@ -348,6 +348,10 @@ func doNormDecomposed(i *Iter) []byte {
if i.info.ccc == 0 { if i.info.ccc == 0 {
break break
} }
if s := i.rb.ss.next(i.info); s == ssOverflow {
i.next = nextCGJDecompose
break
}
} }
// new segment or too many combining characters: exit normalization // new segment or too many combining characters: exit normalization
return i.buf[:i.rb.flushCopy(i.buf[:])] return i.buf[:i.rb.flushCopy(i.buf[:])]
@ -357,6 +361,7 @@ func nextCGJDecompose(i *Iter) []byte {
i.rb.ss = 0 i.rb.ss = 0
i.rb.insertCGJ() i.rb.insertCGJ()
i.next = nextDecomposed i.next = nextDecomposed
i.rb.ss.first(i.info)
buf := doNormDecomposed(i) buf := doNormDecomposed(i)
return buf return buf
} }
@ -365,7 +370,6 @@ func nextCGJDecompose(i *Iter) []byte {
func nextComposed(i *Iter) []byte { func nextComposed(i *Iter) []byte {
outp, startp := 0, i.p outp, startp := 0, i.p
var prevCC uint8 var prevCC uint8
ss := mkStreamSafe(i.info)
for { for {
if !i.info.isYesC() { if !i.info.isYesC() {
goto doNorm goto doNorm
@ -385,11 +389,12 @@ func nextComposed(i *Iter) []byte {
i.setDone() i.setDone()
break break
} else if i.rb.src._byte(i.p) < utf8.RuneSelf { } else if i.rb.src._byte(i.p) < utf8.RuneSelf {
i.rb.ss = 0
i.next = i.asciiF i.next = i.asciiF
break break
} }
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
if v := ss.next(i.info); v == ssStarter { if v := i.rb.ss.next(i.info); v == ssStarter {
break break
} else if v == ssOverflow { } else if v == ssOverflow {
i.next = nextCGJCompose i.next = nextCGJCompose
@ -401,8 +406,10 @@ func nextComposed(i *Iter) []byte {
} }
return i.returnSlice(startp, i.p) return i.returnSlice(startp, i.p)
doNorm: doNorm:
// reset to start position
i.p = startp i.p = startp
i.info = i.rb.f.info(i.rb.src, i.p) i.info = i.rb.f.info(i.rb.src, i.p)
i.rb.ss.first(i.info)
if i.info.multiSegment() { if i.info.multiSegment() {
d := i.info.Decomposition() d := i.info.Decomposition()
info := i.rb.f.info(input{bytes: d}, 0) info := i.rb.f.info(input{bytes: d}, 0)

View File

@ -324,7 +324,6 @@ func (f *formInfo) quickSpan(src input, i, end int, atEOF bool) (n int, ok bool)
// have an overflow for runes that are starters (e.g. with U+FF9E). // have an overflow for runes that are starters (e.g. with U+FF9E).
switch ss.next(info) { switch ss.next(info) {
case ssStarter: case ssStarter:
ss.first(info)
lastSegStart = i lastSegStart = i
case ssOverflow: case ssOverflow:
return lastSegStart, false return lastSegStart, false
@ -441,6 +440,8 @@ func (f Form) nextBoundary(src input, nsrc int, atEOF bool) int {
} }
return -1 return -1
} }
// TODO: Using streamSafe to determine the boundary isn't the same as
// using BoundaryBefore. Determine which should be used.
if s := ss.next(info); s != ssSuccess { if s := ss.next(info); s != ssSuccess {
return i return i
} }
@ -505,16 +506,15 @@ func decomposeSegment(rb *reorderBuffer, sp int, atEOF bool) int {
if info.size == 0 { if info.size == 0 {
return 0 return 0
} }
if rb.nrune > 0 {
if s := rb.ss.next(info); s == ssStarter { if s := rb.ss.next(info); s == ssStarter {
// TODO: this could be removed if we don't support merging.
if rb.nrune > 0 {
goto end goto end
}
} else if s == ssOverflow { } else if s == ssOverflow {
rb.insertCGJ() rb.insertCGJ()
goto end goto end
} }
} else {
rb.ss.first(info)
}
if err := rb.insertFlush(rb.src, sp, info); err != iSuccess { if err := rb.insertFlush(rb.src, sp, info); err != iSuccess {
return int(err) return int(err)
} }

View File

@ -6,12 +6,11 @@
package rate package rate
import ( import (
"context"
"fmt" "fmt"
"math" "math"
"sync" "sync"
"time" "time"
"golang.org/x/net/context"
) )
// Limit defines the maximum frequency of some events. // Limit defines the maximum frequency of some events.
@ -199,9 +198,10 @@ func (lim *Limiter) Reserve() *Reservation {
// The Limiter takes this Reservation into account when allowing future events. // The Limiter takes this Reservation into account when allowing future events.
// ReserveN returns false if n exceeds the Limiter's burst size. // ReserveN returns false if n exceeds the Limiter's burst size.
// Usage example: // Usage example:
// r, ok := lim.ReserveN(time.Now(), 1) // r := lim.ReserveN(time.Now(), 1)
// if !ok { // if !r.OK() {
// // Not allowed to act! Did you remember to set lim.burst to be > 0 ? // // Not allowed to act! Did you remember to set lim.burst to be > 0 ?
// return
// } // }
// time.Sleep(r.Delay()) // time.Sleep(r.Delay())
// Act() // Act()
@ -221,8 +221,9 @@ func (lim *Limiter) Wait(ctx context.Context) (err error) {
// WaitN blocks until lim permits n events to happen. // WaitN blocks until lim permits n events to happen.
// It returns an error if n exceeds the Limiter's burst size, the Context is // It returns an error if n exceeds the Limiter's burst size, the Context is
// canceled, or the expected wait time exceeds the Context's Deadline. // canceled, or the expected wait time exceeds the Context's Deadline.
// The burst limit is ignored if the rate limit is Inf.
func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) { func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) {
if n > lim.burst { if n > lim.burst && lim.limit != Inf {
return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, lim.burst) return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, lim.burst)
} }
// Check if ctx is already cancelled // Check if ctx is already cancelled
@ -281,9 +282,9 @@ func (lim *Limiter) SetLimitAt(now time.Time, newLimit Limit) {
// reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN. // reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duration) Reservation { func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duration) Reservation {
lim.mu.Lock() lim.mu.Lock()
defer lim.mu.Unlock()
if lim.limit == Inf { if lim.limit == Inf {
lim.mu.Unlock()
return Reservation{ return Reservation{
ok: true, ok: true,
lim: lim, lim: lim,
@ -326,6 +327,7 @@ func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duratio
lim.last = last lim.last = last
} }
lim.mu.Unlock()
return r return r
} }

8
glide.lock generated
View File

@ -1,5 +1,5 @@
hash: b9e05532b0948a89c8f63c21c3ef85b22d1d06755554942056e004849aae1739 hash: 22bec0dcd6fb064a5bb4a88cd9e0e37e3f034ba8a5c7f59288c45c3ee3a2b5d5
updated: 2017-04-17T14:32:27.313252456-07:00 updated: 2017-04-20T11:18:11.503876035-07:00
imports: imports:
- name: github.com/beorn7/perks - name: github.com/beorn7/perks
version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
@ -133,14 +133,14 @@ imports:
subpackages: subpackages:
- unix - unix
- name: golang.org/x/text - name: golang.org/x/text
version: f4b4367115ec2de254587813edaa901bc1c723a8 version: 19e3104b43db45fca0303f489a9536087b184802
subpackages: subpackages:
- secure/bidirule - secure/bidirule
- transform - transform
- unicode/bidi - unicode/bidi
- unicode/norm - unicode/norm
- name: golang.org/x/time - name: golang.org/x/time
version: a4bde12657593d5e90d0533a3e4fd95e635124cb version: c06e80d9300e4443158a03817b8a8cb37d230320
subpackages: subpackages:
- rate - rate
- name: google.golang.org/grpc - name: google.golang.org/grpc

View File

@ -93,7 +93,7 @@ import:
- package: golang.org/x/sys - package: golang.org/x/sys
version: e48874b42435b4347fc52bdee0424a52abc974d7 version: e48874b42435b4347fc52bdee0424a52abc974d7
- package: golang.org/x/time - package: golang.org/x/time
version: a4bde12657593d5e90d0533a3e4fd95e635124cb version: c06e80d9300e4443158a03817b8a8cb37d230320
subpackages: subpackages:
- rate - rate
- package: google.golang.org/grpc - package: google.golang.org/grpc