| 149 | } |
| 150 | |
| 151 | func (z *SGL) Write(p []byte) (n int, err error) { |
| 152 | wlen := len(p) |
| 153 | if needtot := z.woff + int64(wlen); needtot > z.Cap() { |
| 154 | z.grow(needtot) |
| 155 | } |
| 156 | idx, off, poff := z.woff/z.slab.Size(), z.woff%z.slab.Size(), 0 |
| 157 | for wlen > 0 { |
| 158 | size := cos.MinI64(z.slab.Size()-off, int64(wlen)) |
| 159 | buf := z.sgl[idx] |
| 160 | src := p[poff : poff+int(size)] |
| 161 | copy(buf[off:], src) |
| 162 | z.woff += size |
| 163 | idx++ |
| 164 | off = 0 |
| 165 | wlen -= int(size) |
| 166 | poff += int(size) |
| 167 | } |
| 168 | return len(p), nil |
| 169 | } |
| 170 | |
| 171 | func (z *SGL) WriteByte(c byte) error { |
| 172 | if needtot := z.woff + 1; needtot > z.Cap() { |