1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00

simplified Release()

This commit is contained in:
Darien Raymond 2016-12-27 21:06:55 +01:00
parent ea33b7691b
commit 538b0720d5
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package buf
import "io"
import "v2ray.com/core/common"
// BytesToBufferReader is a Reader that adjusts its reading speed automatically.
type BytesToBufferReader struct {
@ -45,7 +46,7 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {
// Release implements Releasable.Release().
func (v *BytesToBufferReader) Release() {
v.reader = nil
common.Release(v.reader)
}
type BufferToBytesReader struct {

View File

@ -1,6 +1,7 @@
package buf
import "io"
import "v2ray.com/core/common"
// BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
type BufferToBytesWriter struct {
@ -25,7 +26,7 @@ func (v *BufferToBytesWriter) Write(buffer *Buffer) error {
// Release implements Releasable.Release().
func (v *BufferToBytesWriter) Release() {
v.writer = nil
common.Release(v.writer)
}
type BytesToBufferWriter struct {

View File

@ -27,9 +27,8 @@ func NewReader(rawReader io.Reader) *BufferedReader {
func (v *BufferedReader) Release() {
v.buffer.Release()
v.buffer = nil
if releasable, ok := v.reader.(common.Releasable); ok {
releasable.Release()
}
common.Release(v.reader)
}
// Cached returns true if the internal cache is effective.

View File

@ -91,7 +91,5 @@ func (v *BufferedWriter) Release() {
v.buffer.Release()
v.buffer = nil
if releasable, ok := v.writer.(common.Releasable); ok {
releasable.Release()
}
common.Release(v.writer)
}

View File

@ -18,3 +18,10 @@ type Releasable interface {
// Release releases all references to accelerate garbage collection.
Release()
}
// Release tries to release the given object.
func Release(v interface{}) {
if releasable, ok := v.(Releasable); ok {
releasable.Release()
}
}