Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed golang-lru to v2 #320

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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