@@ -44,7 +44,30 @@ function M.hash(file)
44
44
end
45
45
46
46
function M .setup ()
47
- M .load ()
47
+ cache = {}
48
+ local f = io.open (cache_path , " rb" )
49
+ if f then
50
+ cache_hash = M .hash (cache_path )
51
+ --- @type string
52
+ local data = f :read (" *a" )
53
+ f :close ()
54
+
55
+ local from = 1
56
+ local to = data :find (" \0 " , from , true )
57
+ while to do
58
+ local key = data :sub (from , to - 1 )
59
+ from = to + 1
60
+ to = data :find (" \0 " , from , true )
61
+ local len = tonumber (data :sub (from , to - 1 ))
62
+ from = to + 1
63
+ cache [key ] = data :sub (from , from + len - 1 )
64
+ from = from + len
65
+ to = data :find (" \0 " , from , true )
66
+ end
67
+ end
68
+ end
69
+
70
+ function M .autosave ()
48
71
vim .api .nvim_create_autocmd (" User" , {
49
72
pattern = " LazyDone" ,
50
73
once = true ,
@@ -77,28 +100,4 @@ function M.save()
77
100
f :close ()
78
101
end
79
102
80
- function M .load ()
81
- cache = {}
82
- local f = io.open (cache_path , " rb" )
83
- if f then
84
- cache_hash = M .hash (cache_path )
85
- --- @type string
86
- local data = f :read (" *a" )
87
- f :close ()
88
-
89
- local from = 1
90
- local to = data :find (" \0 " , from , true )
91
- while to do
92
- local key = data :sub (from , to - 1 )
93
- from = to + 1
94
- to = data :find (" \0 " , from , true )
95
- local len = tonumber (data :sub (from , to - 1 ))
96
- from = to + 1
97
- cache [key ] = data :sub (from , from + len - 1 )
98
- from = from + len
99
- to = data :find (" \0 " , from , true )
100
- end
101
- end
102
- end
103
-
104
103
return M
0 commit comments