MCPcopy
hub / github.com/tdewolff/minify / Peek

Method Peek

xml/buffer.go:43–74  ·  view source on GitHub ↗

Peek returns the ith element and possibly does an allocation. Peeking past an error will panic.

(pos int)

Source from the content-addressed store, hash-verified

41// Peek returns the ith element and possibly does an allocation.
42// Peeking past an error will panic.
43func (z *TokenBuffer) Peek(pos int) *Token {
44 pos += z.pos
45 if pos >= len(z.buf) {
46 if len(z.buf) > 0 && z.buf[len(z.buf)-1].TokenType == xml.ErrorToken {
47 return &z.buf[len(z.buf)-1]
48 }
49
50 c := cap(z.buf)
51 d := len(z.buf) - z.pos
52 p := pos - z.pos + 1 // required peek length
53 var buf []Token
54 if 2*p > c {
55 buf = make([]Token, 0, 2*c+p)
56 } else {
57 buf = z.buf
58 }
59 copy(buf[:d], z.buf[z.pos:])
60
61 buf = buf[:p]
62 pos -= z.pos
63 for i := d; i < p; i++ {
64 z.read(&buf[i])
65 if buf[i].TokenType == xml.ErrorToken {
66 buf = buf[:i+1]
67 pos = i
68 break
69 }
70 }
71 z.pos, z.buf = 0, buf
72 }
73 return &z.buf[pos]
74}
75
76// Shift returns the first element and advances position.
77func (z *TokenBuffer) Shift() *Token {

Callers 2

TestBufferFunction · 0.95
MinifyMethod · 0.95

Calls 3

readMethod · 0.95
lenFunction · 0.85
copyFunction · 0.50

Tested by 1

TestBufferFunction · 0.76