Skip to content

Commit

Permalink
Merge pull request #320 from noborus/golang-lru-v2
Browse files Browse the repository at this point in the history
changed golang-lru to v2
  • Loading branch information
noborus committed Apr 26, 2023
2 parents 46ac68c + c2e344d commit 8aaa488
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/atotto/clipboard v0.1.4
github.com/fsnotify/fsnotify v1.6.0
github.com/gdamore/tcell/v2 v2.6.0
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/golang-lru/v2 v2.0.2
github.com/jwalton/gchalk v1.3.0
github.com/klauspost/compress v1.16.5
github.com/mattn/go-runewidth v0.0.14
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU=
github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
9 changes: 4 additions & 5 deletions oviewer/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync/atomic"
"time"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/noborus/guesswidth"
)

Expand All @@ -36,7 +36,7 @@ type Document struct {
// Specifies the chunk to read. -1 reads the new last line.
ctlCh chan controlSpecifier

cache *lru.Cache
cache *lru.Cache[int, LineC]

ticker *time.Ticker
tickerDone chan struct{}
Expand Down Expand Up @@ -158,7 +158,7 @@ func NewChunk(start int64) *chunk {

// NewCache creates a new cache.
func (m *Document) NewCache() error {
cache, err := lru.New(1024)
cache, err := lru.New[int, LineC](1024)
if err != nil {
return fmt.Errorf("new cache %w", err)
}
Expand Down Expand Up @@ -335,8 +335,7 @@ func (m *Document) contents(lN int, tabWidth int) (contents, error) {
// getLineC returns contents from line number and tabWidth.
// If the line number does not exist, EOF content is returned.
func (m *Document) getLineC(lN int, tabWidth int) (LineC, bool) {
if v, ok := m.cache.Get(lN); ok {
line := v.(LineC)
if line, ok := m.cache.Get(lN); ok {
lc := make(contents, len(line.lc))
copy(lc, line.lc)
line.lc = lc
Expand Down
2 changes: 1 addition & 1 deletion oviewer/oviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ func (root *Root) debugNumOfChunk() {
var loaded []string
for n, chunk := range doc.chunks {
if len(chunk.lines) != 0 {
loaded = append(loaded, strconv.Itoa(n))
loaded = append(loaded, strconv.Itoa(n)+":"+strconv.Itoa(len(chunk.lines)))
}
}
root.debugMessage(fmt.Sprintf("%s: number of chunks %d", doc.FileName, len(doc.chunks)))
Expand Down

0 comments on commit 8aaa488

Please sign in to comment.