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:
parent
ea33b7691b
commit
538b0720d5
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user