]> Sergey Matveev's repositories - btrtrc.git/blobdiff - torrent.go
mmap_span: Avoid allocating the span slice on every use
[btrtrc.git] / torrent.go
index 07f7b0b696a0b7d83efcf57e0aed89789ac42bc2..56b738a8d1d3922632dd669e42890832c31a991b 100644 (file)
@@ -60,7 +60,7 @@ type torrent struct {
        length                      int64
        // Prevent mutations to Data memory maps while in use as they're not safe.
        dataLock sync.RWMutex
-       Data     mmap_span.MMapSpan
+       Data     *mmap_span.MMapSpan
 
        Info *MetaInfo
        // Active peer connections.
@@ -459,8 +459,10 @@ func (t *torrent) Close() (err error) {
        t.CeaseNetworking()
        close(t.closing)
        t.dataLock.Lock()
-       t.Data.Close()
-       t.Data = nil
+       if t.Data != nil {
+               t.Data.Close()
+               t.Data = nil
+       }
        t.dataLock.Unlock()
        for _, conn := range t.Conns {
                conn.Close()