summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2015-06-14 17:34:02 +0200
committerSilvan Jegen <s.jegen@gmail.com>2015-06-14 17:34:02 +0200
commit4b6c9b539466dbec8b0b8cde1f1e2aa67677f6e9 (patch)
treee2626ffa18fbc8b8fe2e4c0421d3e11395274e55
parentb4db27668a5524b3a311cd6eed0eb0ade04b5e6e (diff)
Change usage of copy()
Copy copies the smaller of len(src) and len(dst). We can leverage this behaviour to avoid using extra elses.
-rw-r--r--unxml.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/unxml.go b/unxml.go
index fee5690..a312410 100644
--- a/unxml.go
+++ b/unxml.go
@@ -164,17 +164,14 @@ func (r *ElementReader) Read(out []byte) (int, error) {
continue
}
text := r.xr.tokenizer.Text()
- lentext := len(text)
- if lentext < lenout {
- //fmt.Printf("HAD SPACE: %q, count: %d\n", text, r.xr.count)
- n = copy(out[r.xr.count:], text)
- r.xr.count += n
- lenout -= n
- } else {
+ //fmt.Printf("HAD SPACE: %q, count: %d\n", text, r.xr.count)
+ n = copy(out[r.xr.count:], text)
+ r.xr.count += n
+ lenout -= n
+ if n < len(text) {
//fmt.Printf("HAD NO SPACE: wrote: %q, count: %d, lenout: %d\n", text[:lenout], r.xr.count, lenout)
- n = copy(out[r.xr.count:], text[:lenout])
- r.xr.count += n
- r.xr.lastread = text[lenout:]
+ r.xr.lastread = text[n:]
+ //fmt.Printf("lastread is now: %q\n", text[lenout:])
return r.xr.count, err
}