Selaa lähdekoodia

Use json.Encoder for container.toDisk

* for simmetry with fromDisk
* it might be slightly better for GC because of internal sync.Pool

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Alexander Morozov 9 vuotta sitten
vanhempi
commit
cf02b369e0
1 muutettua tiedostoa jossa 7 lisäystä ja 3 poistoa
  1. 7 3
      daemon/container.go

+ 7 - 3
daemon/container.go

@@ -112,17 +112,21 @@ func (container *Container) fromDisk() error {
 }
 
 func (container *Container) toDisk() error {
-	data, err := json.Marshal(container)
+	pth, err := container.jsonPath()
 	if err != nil {
 		return err
 	}
 
-	pth, err := container.jsonPath()
+	jsonSource, err := os.Create(pth)
 	if err != nil {
 		return err
 	}
+	defer jsonSource.Close()
+
+	enc := json.NewEncoder(jsonSource)
 
-	if err := ioutil.WriteFile(pth, data, 0666); err != nil {
+	// Save container settings
+	if err := enc.Encode(container); err != nil {
 		return err
 	}