Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1955)

Side by Side Diff: src/pkg/encoding/git85/git.go

Issue 1326042: code review 1326042: changes &x -> x[0:] for array to slice conversion (Closed)
Patch Set: code review 1326042: changes &x -> x[0:] for array to slice conversion Created 14 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/encoding/base64/base64.go ('k') | src/pkg/exec/exec.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package git85 implements the radix 85 data encoding 5 // Package git85 implements the radix 85 data encoding
6 // used in the Git version control system. 6 // used in the Git version control system.
7 package git85 7 package git85
8 8
9 import ( 9 import (
10 "bytes" 10 "bytes"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 var i int 170 var i int
171 for i = 0; i < len(p) && e.nbuf < 52; i++ { 171 for i = 0; i < len(p) && e.nbuf < 52; i++ {
172 e.buf[e.nbuf] = p[i] 172 e.buf[e.nbuf] = p[i]
173 e.nbuf++ 173 e.nbuf++
174 } 174 }
175 n += i 175 n += i
176 p = p[i:] 176 p = p[i:]
177 if e.nbuf < 52 { 177 if e.nbuf < 52 {
178 return 178 return
179 } 179 }
180 » » nout := Encode(&e.out, &e.buf) 180 » » nout := Encode(e.out[0:], e.buf[0:])
181 if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil { 181 if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
182 return n, e.err 182 return n, e.err
183 } 183 }
184 e.nbuf = 0 184 e.nbuf = 0
185 } 185 }
186 186
187 // Large interior chunks. 187 // Large interior chunks.
188 for len(p) >= 52 { 188 for len(p) >= 52 {
189 nn := len(e.out) / (1 + 52/4*5 + 1) * 52 189 nn := len(e.out) / (1 + 52/4*5 + 1) * 52
190 if nn > len(p) { 190 if nn > len(p) {
191 nn = len(p) / 52 * 52 191 nn = len(p) / 52 * 52
192 } 192 }
193 if nn > 0 { 193 if nn > 0 {
194 » » » nout := Encode(&e.out, p[0:nn]) 194 » » » nout := Encode(e.out[0:], p[0:nn])
195 if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil { 195 if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
196 return n, e.err 196 return n, e.err
197 } 197 }
198 } 198 }
199 n += nn 199 n += nn
200 p = p[nn:] 200 p = p[nn:]
201 } 201 }
202 202
203 // Trailing fringe. 203 // Trailing fringe.
204 for i := 0; i < len(p); i++ { 204 for i := 0; i < len(p); i++ {
205 e.buf[i] = p[i] 205 e.buf[i] = p[i]
206 } 206 }
207 e.nbuf = len(p) 207 e.nbuf = len(p)
208 n += len(p) 208 n += len(p)
209 return 209 return
210 } 210 }
211 211
212 func (e *encoder) Close() os.Error { 212 func (e *encoder) Close() os.Error {
213 // If there's anything left in the buffer, flush it out 213 // If there's anything left in the buffer, flush it out
214 if e.err == nil && e.nbuf > 0 { 214 if e.err == nil && e.nbuf > 0 {
215 » » nout := Encode(&e.out, e.buf[0:e.nbuf]) 215 » » nout := Encode(e.out[0:], e.buf[0:e.nbuf])
216 e.nbuf = 0 216 e.nbuf = 0
217 _, e.err = e.w.Write(e.out[0:nout]) 217 _, e.err = e.w.Write(e.out[0:nout])
218 } 218 }
219 return e.err 219 return e.err
220 } 220 }
221 221
222 // NewDecoder returns a new Git base85 stream decoder. 222 // NewDecoder returns a new Git base85 stream decoder.
223 func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} } 223 func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} }
224 224
225 type decoder struct { 225 type decoder struct {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // Read and decode more input. 258 // Read and decode more input.
259 var nn int 259 var nn int
260 nn, d.readErr = d.r.Read(d.buf[d.nbuf:]) 260 nn, d.readErr = d.r.Read(d.buf[d.nbuf:])
261 d.nbuf += nn 261 d.nbuf += nn
262 262
263 // Send complete lines to Decode. 263 // Send complete lines to Decode.
264 nl := bytes.LastIndex(d.buf[0:d.nbuf], newline) 264 nl := bytes.LastIndex(d.buf[0:d.nbuf], newline)
265 if nl < 0 { 265 if nl < 0 {
266 continue 266 continue
267 } 267 }
268 » » nn, d.err = Decode(&d.outbuf, d.buf[0:nl+1]) 268 » » nn, d.err = Decode(d.outbuf[0:], d.buf[0:nl+1])
269 if e, ok := d.err.(CorruptInputError); ok { 269 if e, ok := d.err.(CorruptInputError); ok {
270 d.err = CorruptInputError(int64(e) + d.off) 270 d.err = CorruptInputError(int64(e) + d.off)
271 } 271 }
272 d.out = d.outbuf[0:nn] 272 d.out = d.outbuf[0:nn]
273 » » d.nbuf = copy(&d.buf, d.buf[nl+1:d.nbuf]) 273 » » d.nbuf = copy(d.buf[0:], d.buf[nl+1:d.nbuf])
274 d.off += int64(nl + 1) 274 d.off += int64(nl + 1)
275 } 275 }
276 panic("unreacahable") 276 panic("unreacahable")
277 } 277 }
OLDNEW
« no previous file with comments | « src/pkg/encoding/base64/base64.go ('k') | src/pkg/exec/exec.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b