LCOV - code coverage report
Current view: top level - pebble/internal/cache - value.go (source / functions) Hit Total Coverage
Test: 2023-10-15 08:16Z bbbf3df1 - meta test only.lcov Lines: 16 18 88.9 %
Date: 2023-10-15 08:17:32 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : package cache
       6             : 
       7             : // Value holds a reference counted immutable value.
       8             : type Value struct {
       9             :         buf []byte
      10             :         // Reference count for the value. The value is freed when the reference count
      11             :         // drops to zero.
      12             :         ref refcnt
      13             : }
      14             : 
      15             : // Buf returns the buffer associated with the value. The contents of the buffer
      16             : // should not be changed once the value has been added to the cache. Instead, a
      17             : // new Value should be created and added to the cache to replace the existing
      18             : // value.
      19           1 : func (v *Value) Buf() []byte {
      20           1 :         if v == nil {
      21           0 :                 return nil
      22           0 :         }
      23           1 :         return v.buf
      24             : }
      25             : 
      26             : // Truncate the buffer to the specified length. The buffer length should not be
      27             : // changed once the value has been added to the cache as there may be
      28             : // concurrent readers of the Value. Instead, a new Value should be created and
      29             : // added to the cache to replace the existing value.
      30           1 : func (v *Value) Truncate(n int) {
      31           1 :         v.buf = v.buf[:n]
      32           1 : }
      33             : 
      34           1 : func (v *Value) refs() int32 {
      35           1 :         return v.ref.refs()
      36           1 : }
      37             : 
      38           1 : func (v *Value) acquire() {
      39           1 :         v.ref.acquire()
      40           1 : }
      41             : 
      42           1 : func (v *Value) release() {
      43           1 :         if v != nil && v.ref.release() {
      44           1 :                 v.free()
      45           1 :         }
      46             : }

Generated by: LCOV version 1.14