From 566876ba251e35cdfc84392b3d11bd0b33b2626b Mon Sep 17 00:00:00 2001 From: MURAOKA Taro Date: Mon, 20 Dec 2021 01:59:48 +0900 Subject: [PATCH] cache tags-xx as JSON file for speed --- tools/makehtml.vim | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tools/makehtml.vim b/tools/makehtml.vim index 2d3f8fb9e..8c394dc27 100644 --- a/tools/makehtml.vim +++ b/tools/makehtml.vim @@ -38,6 +38,10 @@ function! MakeHtmlAll(...) endif endfunction +function! s:JsonName(lang) + return a:lang == "" ? "tags.json" : printf("tags-%s.json", a:lang) +endfunction + function! MakeTagsFile() let files = split(glob('tags'), '\n') let files += split(glob('tags-??'), '\n') @@ -50,7 +54,7 @@ function! MakeTagsFile() endif silent new `=fname` silent %delete _ - let tags = s:GetTags(lang) + let tags = s:LoadTags(lang) for tagname in sort(keys(tags)) if tagname == "help-tags" continue @@ -60,6 +64,8 @@ function! MakeTagsFile() call append('$', ' vim:ft=help:') silent 1delete _ silent wq! + " save JSON tag cache + call writefile([js_encode(tags)], s:JsonName(lang), "s") endfor endfunction @@ -216,26 +222,36 @@ endfunction function! s:GetTags(lang) if !exists("s:tags_" . a:lang) - let &l:tags = (a:lang == "") ? "./tags" : "./tags-" . a:lang - let tags = {} - for item in taglist(".*") - let item["html"] = s:HtmlName(item["filename"]) - let tags[item["name"]] = item - endfor - " for help-tags - let item = {} - let item["name"] = "help-tags" - if s:IsSingleMode() - let item["html"] = "tags.html" + " try to load JSON tag cache + let jsonname = s:JsonName(a:lang) + if filereadable(jsonname) + let s:tags_{a:lang} = js_decode(readfile(jsonname)[0]) else - let item["html"] = printf("tags%s.html", (a:lang == "") ? "" : "." . a:lang) + let s:tags_{a:lang} = s:LoadTags(a:lang) endif - let tags[item["name"]] = item - let s:tags_{a:lang} = tags endif return s:tags_{a:lang} endfunction +func s:LoadTags(lang) + let &l:tags = (a:lang == "") ? "./tags" : "./tags-" . a:lang + let tags = {} + for item in taglist(".*") + let item["html"] = s:HtmlName(item["filename"]) + let tags[item["name"]] = item + endfor + " for help-tags + let item = {} + let item["name"] = "help-tags" + if s:IsSingleMode() + let item["html"] = "tags.html" + else + let item["html"] = printf("tags%s.html", (a:lang == "") ? "" : "." . a:lang) + endif + let tags[item["name"]] = item + return tags +endfunction + function! s:IsSingleMode() " if there is one language files, do not append language identifier " (use "help.html" instead of "help.ab.html").