Browse code

Avoid back and forth conversion between strings and bytes.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>
(cherry picked from commit d6d448aab8e303a351b763f6a77b909fadb7344b)

Anusha Ragunathan authored on 2016/06/16 01:17:05
Showing 1 changed files
... ...
@@ -1,21 +1,20 @@
1 1
 package cli
2 2
 
3
-import "bytes"
3
+import "strings"
4 4
 
5 5
 // Errors is a list of errors.
6 6
 // Useful in a loop if you don't want to return the error right away and you want to display after the loop,
7 7
 // all the errors that happened during the loop.
8 8
 type Errors []error
9 9
 
10
-func (errs Errors) Error() string {
11
-	if len(errs) < 1 {
10
+func (errList Errors) Error() string {
11
+	if len(errList) < 1 {
12 12
 		return ""
13 13
 	}
14
-	var buf bytes.Buffer
15
-	buf.WriteString(errs[0].Error())
16
-	for _, err := range errs[1:] {
17
-		buf.WriteString(", ")
18
-		buf.WriteString(err.Error())
14
+
15
+	out := make([]string, len(errList))
16
+	for i := range errList {
17
+		out[i] = errList[i].Error()
19 18
 	}
20
-	return buf.String()
19
+	return strings.Join(out, ", ")
21 20
 }