diff --git a/cmd/minio-decode/main.go b/cmd/minio-decode/main.go index c40458118..822885903 100644 --- a/cmd/minio-decode/main.go +++ b/cmd/minio-decode/main.go @@ -80,10 +80,9 @@ func main() { // set up encoder erasureParameters, _ := erasure.ValidateParams(k, m, 8, erasure.CAUCHY) - encoder := erasure.NewEncoder(erasureParameters) // decode data - decodedData, err := encoder.Decode(chunks, length) + decodedData, err := erasure.Decode(chunks, erasureParameters, length) if err != nil { log.Fatal(err) } diff --git a/cmd/minio-encode/main.go b/cmd/minio-encode/main.go index 9d9cb2851..5c71450cd 100644 --- a/cmd/minio-encode/main.go +++ b/cmd/minio-encode/main.go @@ -71,10 +71,8 @@ func main() { // set up encoder erasureParameters, _ := erasure.ValidateParams(k, m, 8, erasure.CAUCHY) - encoder := erasure.NewEncoder(erasureParameters) - // encode data - encodedData, length := encoder.Encode(input) + encodedData, length := erasure.Encode(input, erasureParameters) // write encoded data out for key, data := range encodedData { diff --git a/erasure/cauchy_test.go b/erasure/cauchy_test.go index 8b3dd481c..42ac5df36 100644 --- a/erasure/cauchy_test.go +++ b/erasure/cauchy_test.go @@ -29,10 +29,8 @@ func Test(t *testing.T) { TestingT(t) } func (s *MySuite) TestCachyEncode(c *C) { ep, _ := ValidateParams(10, 5, 8, CAUCHY) - p := NewEncoder(ep) - data := make([]byte, 1000) - _, length := p.Encode(data) + _, length := Encode(data, ep) c.Assert(length, Equals, len(data)) } @@ -41,8 +39,7 @@ func (s *MySuite) TestCauchyDecode(c *C) { data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.") - p := NewEncoder(ep) - chunks, length := p.Encode(data) + chunks, length := Encode(data, ep) c.Assert(length, Equals, len(data)) chunks[0] = nil @@ -51,7 +48,7 @@ func (s *MySuite) TestCauchyDecode(c *C) { chunks[9] = nil chunks[13] = nil - recovered_data, err := p.Decode(chunks, length) + recovered_data, err := Decode(chunks, ep, length) c.Assert(err, Not(IsNil)) c.Assert(recovered_data, DeepEquals, data) diff --git a/erasure/decode.go b/erasure/decode.go index f9fb6dd82..46a973874 100644 --- a/erasure/decode.go +++ b/erasure/decode.go @@ -108,6 +108,6 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) { return recovered_output[:length], nil } -func Decode(chunks [][]byte, ep EncoderParams, length int) (block []byte, err error) { +func Decode(chunks [][]byte, ep *EncoderParams, length int) (block []byte, err error) { return GetEncoder(ep).Decode(chunks, length) } diff --git a/erasure/encode.go b/erasure/encode.go index 164066a88..f48bc045b 100644 --- a/erasure/encode.go +++ b/erasure/encode.go @@ -200,10 +200,10 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) { return chunks, block_len } -func GetEncoder(ep EncoderParams) *Encoder { +func GetEncoder(ep *EncoderParams) *Encoder { return DefaultCache.GetC(ep) } -func Encode(data []byte, ep EncoderParams) (chunks [][]byte, length int) { +func Encode(data []byte, ep *EncoderParams) (chunks [][]byte, length int) { return GetEncoder(ep).Encode(data) } diff --git a/erasure/lru.go b/erasure/lru.go index 23934b995..a9a02df2a 100644 --- a/erasure/lru.go +++ b/erasure/lru.go @@ -37,17 +37,17 @@ func GetCache(capacity int) *Cache { } // ``GetC()`` -- Grab encoder from LRU -func (c *Cache) GetC(ep EncoderParams) *Encoder { +func (c *Cache) GetC(ep *EncoderParams) *Encoder { if encoder, ret := c._Get(ep); ret { return encoder } - encoder := NewEncoder(&ep) + encoder := NewEncoder(ep) c._Put(ep, encoder) return encoder } // ``_Get()`` -- Get key from existing LRU -func (c *Cache) _Get(ep EncoderParams) (*Encoder, bool) { +func (c *Cache) _Get(ep *EncoderParams) (*Encoder, bool) { c.mutex.RLock() defer c.mutex.RUnlock() if encoder, ret := c.cache.Get(ep); ret { @@ -57,7 +57,7 @@ func (c *Cache) _Get(ep EncoderParams) (*Encoder, bool) { } // ``_Put()`` -- Add key to existing LRU -func (c *Cache) _Put(ep EncoderParams, encoder *Encoder) { +func (c *Cache) _Put(ep *EncoderParams, encoder *Encoder) { c.mutex.Lock() defer c.mutex.Unlock() c.cache.Add(ep, encoder)