Skip to content

Commit 28e7f51

Browse files
committed
Do not call type() repeatedly.
1 parent aff802c commit 28e7f51

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

autoload/vital/__vital__/Web/JSON.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ function! s:encode(val, ...) abort
8080
\ 'indent': 0,
8181
\}, get(a:000, 0, {})
8282
\)
83-
if type(a:val) == 0
83+
let t = type(a:val)
84+
if t == 0
8485
return a:val
85-
elseif type(a:val) == 1
86+
elseif t == 1
8687
let json = '"' . escape(a:val, '\"') . '"'
8788
let json = substitute(json, "\r", '\\r', 'g')
8889
let json = substitute(json, "\n", '\\n', 'g')
8990
let json = substitute(json, "\t", '\\t', 'g')
9091
return iconv(json, &encoding, 'utf-8')
91-
elseif type(a:val) == 2
92+
elseif t == 2
9293
if s:const.true == a:val
9394
return 'true'
9495
elseif s:const.false == a:val
@@ -99,9 +100,9 @@ function! s:encode(val, ...) abort
99100
" backward compatibility
100101
return string(a:val)
101102
endif
102-
elseif type(a:val) == 3
103+
elseif t == 3
103104
return s:_encode_list(a:val, settings)
104-
elseif type(a:val) == 4
105+
elseif t == 4
105106
return s:_encode_dict(a:val, settings)
106107
else
107108
return string(a:val)

0 commit comments

Comments
 (0)