@@ -7,7 +7,6 @@ if type(package.loaded["vim.cache"]) == "table" then
7
7
return package.loaded [" vim.cache" ]
8
8
end
9
9
10
- local ffi = require (" ffi" )
11
10
local uv = vim .loop
12
11
13
12
local M = {}
@@ -20,7 +19,7 @@ local M = {}
20
19
--- @field patterns ? string[] Paterns to use (defaults to ` {"/init.lua", ".lua"}` )
21
20
--- @field paths ? string[] Extra paths to search for modname
22
21
23
- M .VERSION = 2
22
+ M .VERSION = 3
24
23
M .path = vim .fn .stdpath (" cache" ) .. " /luac"
25
24
M .enabled = false
26
25
--- @type table<string , { total : number , time : number , [string] : number ?}? >
@@ -114,7 +113,7 @@ function Cache.write(name, entry)
114
113
entry .hash .mtime .sec ,
115
114
entry .hash .mtime .nsec ,
116
115
}
117
- uv .fs_write (f , ffi . string ( ffi . new ( " const uint32_t[4] " , header ), 16 ) )
116
+ uv .fs_write (f , table.concat ( header , " , " ) .. " \0 " )
118
117
uv .fs_write (f , entry .chunk )
119
118
uv .fs_close (f )
120
119
end
@@ -132,15 +131,17 @@ function Cache.read(name)
132
131
local data = uv .fs_read (f , hash .size , 0 ) --[[ @as string]]
133
132
uv .fs_close (f )
134
133
134
+ local zero = data :find (" \0 " , 1 , true )
135
+
135
136
--- @type integer[] |{ [0] : integer }
136
- local header = ffi . cast ( " uint32_t* " , ffi . new ( " const char[16] " , data :sub (1 , 16 )) )
137
- if header [0 ] ~= M .VERSION then
137
+ local header = vim . split ( data :sub (1 , zero - 1 ), " , " )
138
+ if tonumber ( header [1 ]) ~= M .VERSION then
138
139
return
139
140
end
140
- M .track (" read" , start )
141
+ M ._track (" read" , start )
141
142
return {
142
- hash = { size = header [1 ] , mtime = { sec = header [2 ] , nsec = header [3 ] } },
143
- chunk = data :sub (16 + 1 ),
143
+ hash = { size = tonumber ( header [2 ]) , mtime = { sec = tonumber ( header [3 ]) , nsec = tonumber ( header [4 ]) } },
144
+ chunk = data :sub (zero + 1 ),
144
145
}
145
146
end
146
147
M ._track (" read" , start )
0 commit comments