patch 9.1.0564: id() can be faster

Commit: 
https://github.com/vim/vim/commit/0512425891c9bf350531f7c53be5e4126d1a6548
Author: Ernie Rael <err...@raelity.com>
Date:   Thu Jul 11 22:10:45 2024 +0200

    patch 9.1.0564: id() can be faster
    
    Problem:  id() can be made faster
    Solution: don't use printf(), use clever shift of pointer
              (Ernie Rael)
    
    closes: #15207
    
    Signed-off-by: Ernie Rael <err...@raelity.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 96d774e7e..b25bb9390 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -309,7 +309,7 @@ hlget([{name} [, {resolve}]])       List    get highlight 
group attributes
 hlset({list})                  Number  set highlight group attributes
 hostname()                     String  name of the machine Vim is running on
 iconv({expr}, {from}, {to})    String  convert encoding of {expr}
-id({item})                     String  get address of item as a string
+id({item})                     String  get unique identity string of item
 indent({lnum})                 Number  indent of line {lnum}
 index({object}, {expr} [, {start} [, {ic}]])
                                Number  index in {object} where {expr} appears
diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index ee3301a10..8ea2c1c13 100644
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -3,7 +3,7 @@
 " Maintainer:     Hirohito Higashi <h.east.727 ATMARK gmail.com>
 "         Doug Kearns <dougkea...@gmail.com>
 " URL:    https://github.com/vim-jp/syntax-vim-ex
-" Last Change:    2024 Jul 05
+" Last Change:    2024 Jul 11
 " Former Maintainer: Charles E. Campbell
 
 " DO NOT CHANGE DIRECTLY.
@@ -89,7 +89,7 @@ syn keyword vimErrSetting contained invakm invaltkeymap 
invanti invantialias inv
 syn case ignore
 " GEN_SYN_VIM: vimAutoEvent, START_STR='syn keyword vimAutoEvent contained', 
END_STR=''
 syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter 
BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd 
BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite 
BufWriteCmd BufWritePost BufWritePre CmdlineChanged CmdlineEnter CmdlineLeave 
CmdUndefined CmdwinEnter CmdwinLeave ColorScheme ColorSchemePre CompleteChanged 
CompleteDone CompleteDonePre CursorHold CursorHoldI CursorMoved CursorMovedC 
CursorMovedI DiffUpdated DirChanged DirChangedPre EncodingChanged ExitPre 
FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell 
FileChangedShellPost FileEncoding FileReadCmd FileReadPost FileReadPre FileType 
FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre 
FilterWritePost
-syn keyword vimAutoEvent contained FilterWritePre FocusGained FocusLost 
FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter 
InsertLeave InsertLeavePre MenuPopup ModeChanged OptionSet QuickFixCmdPost 
QuickFixCmdPre QuitPre RemoteReply SafeState SafeStateAgain SessionLoadPost 
SessionWritePost ShellCmdPost ShellFilterPost SigUSR1 SourceCmd SourcePost 
SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax 
TabClosed TabEnter TabLeave TabNew TermChanged TerminalOpen TerminalWinOpen 
TermResponse TermResponseAll TextChanged TextChangedI TextChangedP TextChangedT 
TextYankPost User VimEnter VimLeave VimLeavePre VimResized VimResume VimSuspend 
WinClosed WinEnter WinLeave WinNew WinNewPre WinResized WinScrolled
+syn keyword vimAutoEvent contained FilterWritePre FocusGained FocusLost 
FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter 
InsertLeave InsertLeavePre KeyInputPre MenuPopup ModeChanged OptionSet 
QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SafeState SafeStateAgain 
SessionLoadPost SessionWritePost ShellCmdPost ShellFilterPost SigUSR1 SourceCmd 
SourcePost SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists 
Syntax TabClosed TabEnter TabLeave TabNew TermChanged TerminalOpen 
TerminalWinOpen TermResponse TermResponseAll TextChanged TextChangedI 
TextChangedP TextChangedT TextYankPost User VimEnter VimLeave VimLeavePre 
VimResized VimResume VimSuspend WinClosed WinEnter WinLeave WinNew WinNewPre 
WinResized WinScrolled
 
 " Highlight commonly used Groupnames {{{2
 syn keyword vimGroup contained Comment Constant String Character Number 
Boolean Float Identifier Function Statement Conditional Repeat Label Operator 
Keyword Exception PreProc Include Define Macro PreCondit Type StorageClass 
Structure Typedef Special SpecialChar Tag Delimiter SpecialComment Debug 
Underlined Ignore Error Todo
@@ -104,7 +104,7 @@ syn case match
 " GEN_SYN_VIM: vimFuncName, START_STR='syn keyword vimFuncName contained', 
END_STR=''
 syn keyword vimFuncName contained abs acos add and append appendbufline argc 
argidx arglistid argv asin assert_beeps assert_equal assert_equalfile 
assert_exception assert_fails assert_false assert_inrange assert_match 
assert_nobeep assert_notequal assert_notmatch assert_report assert_true atan 
atan2 autocmd_add autocmd_delete autocmd_get balloon_gettext balloon_show 
balloon_split bindtextdomain blob2list browse browsedir bufadd bufexists 
buflisted bufload bufloaded bufname bufnr bufwinid bufwinnr byte2line byteidx 
byteidxcomp call ceil ch_canread ch_close ch_close_in ch_evalexpr ch_evalraw 
ch_getbufnr ch_getjob ch_info ch_log ch_logfile ch_open ch_read ch_readblob 
ch_readraw ch_sendexpr ch_sendraw ch_setoptions ch_status changenr char2nr 
charclass charcol charidx
 syn keyword vimFuncName contained chdir cindent clearmatches col complete 
complete_add complete_check complete_info confirm copy cos cosh count 
cscope_connection cursor debugbreak deepcopy delete deletebufline did_filetype 
diff diff_filler diff_hlID digraph_get digraph_getlist digraph_set 
digraph_setlist echoraw empty environ err_teapot escape eval eventhandler 
executable execute exepath exists exists_compiled exp expand expandcmd extend 
extendnew feedkeys filecopy filereadable filewritable filter finddir findfile 
flatten flattennew float2nr floor fmod fnameescape fnamemodify foldclosed 
foldclosedend foldlevel foldtext foldtextresult foreach foreground fullcommand 
funcref function garbagecollect get getbufinfo getbufline getbufoneline 
getbufvar getcellwidths getchangelist
-syn keyword vimFuncName contained getchar getcharmod getcharpos getcharsearch 
getcharstr getcmdcompltype getcmdline getcmdpos getcmdscreenpos getcmdtype 
getcmdwintype getcompletion getcurpos getcursorcharpos getcwd getenv 
getfontname getfperm getfsize getftime getftype getimstatus getjumplist getline 
getloclist getmarklist getmatches getmousepos getmouseshape getpid getpos 
getqflist getreg getreginfo getregion getregionpos getregtype getscriptinfo 
gettabinfo gettabvar gettabwinvar gettagstack gettext getwininfo getwinpos 
getwinposx getwinposy getwinvar glob glob2regpat globpath has has_key 
haslocaldir hasmapto histadd histdel histget histnr hlID hlexists hlget hlset 
hostname iconv indent index indexof input inputdialog inputlist inputrestore 
inputsave inputsecret
+syn keyword vimFuncName contained getchar getcharmod getcharpos getcharsearch 
getcharstr getcmdcompltype getcmdline getcmdpos getcmdscreenpos getcmdtype 
getcmdwintype getcompletion getcurpos getcursorcharpos getcwd getenv 
getfontname getfperm getfsize getftime getftype getimstatus getjumplist getline 
getloclist getmarklist getmatches getmousepos getmouseshape getpid getpos 
getqflist getreg getreginfo getregion getregionpos getregtype getscriptinfo 
gettabinfo gettabvar gettabwinvar gettagstack gettext getwininfo getwinpos 
getwinposx getwinposy getwinvar glob glob2regpat globpath has has_key 
haslocaldir hasmapto histadd histdel histget histnr hlID hlexists hlget hlset 
hostname iconv id indent index indexof input inputdialog inputlist inputrestore 
inputsave inputsecret
 syn keyword vimFuncName contained insert instanceof interrupt invert 
isabsolutepath isdirectory isinf islocked isnan items job_getchannel job_info 
job_setoptions job_start job_status job_stop join js_decode js_encode 
json_decode json_encode keys keytrans len libcall libcallnr line line2byte 
lispindent list2blob list2str listener_add listener_flush listener_remove 
localtime log log10 luaeval map maparg mapcheck maplist mapnew mapset match 
matchadd matchaddpos matcharg matchbufline matchdelete matchend matchfuzzy 
matchfuzzypos matchlist matchstr matchstrlist matchstrpos max menu_info min 
mkdir mode mzeval nextnonblank nr2char or pathshorten perleval popup_atcursor 
popup_beval popup_clear popup_close popup_create popup_dialog popup_filter_menu 
popup_filter_yesno
 syn keyword vimFuncName contained popup_findecho popup_findinfo 
popup_findpreview popup_getoptions popup_getpos popup_hide popup_list 
popup_locate popup_menu popup_move popup_notification popup_setbuf 
popup_setoptions popup_settext popup_show pow prevnonblank printf 
prompt_getprompt prompt_setcallback prompt_setinterrupt prompt_setprompt 
prop_add prop_add_list prop_clear prop_find prop_list prop_remove prop_type_add 
prop_type_change prop_type_delete prop_type_get prop_type_list pum_getpos 
pumvisible py3eval pyeval pyxeval rand range readblob readdir readdirex 
readfile reduce reg_executing reg_recording reltime reltimefloat reltimestr 
remote_expr remote_foreground remote_peek remote_read remote_send 
remote_startserver remove rename repeat resolve reverse round
 syn keyword vimFuncName contained rubyeval screenattr screenchar screenchars 
screencol screenpos screenrow screenstring search searchcount searchdecl 
searchpair searchpairpos searchpos server2client serverlist setbufline 
setbufvar setcellwidths setcharpos setcharsearch setcmdline setcmdpos 
setcursorcharpos setenv setfperm setline setloclist setmatches setpos setqflist 
setreg settabvar settabwinvar settagstack setwinvar sha256 shellescape 
shiftwidth sign_define sign_getdefined sign_getplaced sign_jump sign_place 
sign_placelist sign_undefine sign_unplace sign_unplacelist simplify sin sinh 
slice sort sound_clear sound_playevent sound_playfile sound_stop soundfold 
spellbadword spellsuggest split sqrt srand state str2float str2list str2nr 
strcharlen strcharpart strchars
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 7e3241037..52673b48c 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -7537,7 +7537,8 @@ f_hostname(typval_T *argvars UNUSED, typval_T *rettv)
     void
 f_id(typval_T *argvars, typval_T *rettv)
 {
-    char_u     numbuf[NUMBUFLEN];
+    char    numbuf[NUMBUFLEN];
+    char    *p = numbuf;
 
     switch (argvars[0].v_type)
     {
@@ -7549,17 +7550,22 @@ f_id(typval_T *argvars, typval_T *rettv)
        case VAR_BLOB:
            // Assume pointer value in typval_T vval union at common location.
            if (argvars[0].vval.v_object != NULL)
-               vim_snprintf((char*)numbuf, sizeof(numbuf), "%p",
-                                           (void *)argvars[0].vval.v_object);
-           else
-               numbuf[0] = NUL;
-           break;
+           {
+               // "v" gets the address as an integer
+               uintptr_t v = (uintptr_t)(void *)argvars[0].vval.v_object;
+               // Build a hex string from the item's address; it is in
+               // reverse order. Ignore trailing zeros.
+               for (; p < numbuf + sizeof(uintptr_t) * 2 && v != 0;
+                                                               ++p, v >>= 4)
+                   *p = "0123456789abcdef"[v & 0xf];
+           }
        default:
-           numbuf[0] = NUL;
+           break;
     }
+    *p = NUL;
 
     rettv->v_type = VAR_STRING;
-    rettv->vval.v_string = vim_strsave(numbuf);
+    rettv->vval.v_string = vim_strsave((char_u *)numbuf);
 }
 
 /*
diff --git a/src/version.c b/src/version.c
index ff654844f..70254cc43 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    564,
 /**/
     563,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sS0R2-000RPD-QT%40256bit.org.

Raspunde prin e-mail lui