comparison src/syntax.c @ 29071:b90bca860b5a v8.2.5057

patch 8.2.5057: using gettimeofday() for timeout is very inefficient Commit: https://github.com/vim/vim/commit/6574577cacd393ab7591fc776ea060eebc939e55 Author: Paul Ollis <paul@cleversheep.org> Date: Sun Jun 5 16:55:54 2022 +0100 patch 8.2.5057: using gettimeofday() for timeout is very inefficient Problem: Using gettimeofday() for timeout is very inefficient. Solution: Set a platform dependent timer. (Paul Ollis, closes https://github.com/vim/vim/issues/10505)
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Jun 2022 18:00:08 +0200
parents a7556b47ff09
children 48b36959a4fc
comparison
equal deleted inserted replaced
29070:8bf8001ef6d5 29071:b90bca860b5a
264 * When current_state.ga_itemsize is 0 the current state is invalid. 264 * When current_state.ga_itemsize is 0 the current state is invalid.
265 */ 265 */
266 static win_T *syn_win; // current window for highlighting 266 static win_T *syn_win; // current window for highlighting
267 static buf_T *syn_buf; // current buffer for highlighting 267 static buf_T *syn_buf; // current buffer for highlighting
268 static synblock_T *syn_block; // current buffer for highlighting 268 static synblock_T *syn_block; // current buffer for highlighting
269 #ifdef FEAT_RELTIME
270 static proftime_T *syn_tm; // timeout limit
271 #endif
272 static linenr_T current_lnum = 0; // lnum of current state 269 static linenr_T current_lnum = 0; // lnum of current state
273 static colnr_T current_col = 0; // column of current state 270 static colnr_T current_col = 0; // column of current state
274 static int current_state_stored = 0; // TRUE if stored current state 271 static int current_state_stored = 0; // TRUE if stored current state
275 // after setting current_finished 272 // after setting current_finished
276 static int current_finished = 0; // current line has been finished 273 static int current_finished = 0; // current line has been finished
347 static int syn_add_cluster(char_u *name); 344 static int syn_add_cluster(char_u *name);
348 static void init_syn_patterns(void); 345 static void init_syn_patterns(void);
349 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); 346 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci);
350 static int get_id_list(char_u **arg, int keylen, short **list, int skip); 347 static int get_id_list(char_u **arg, int keylen, short **list, int skip);
351 static void syn_combine_list(short **clstr1, short **clstr2, int list_op); 348 static void syn_combine_list(short **clstr1, short **clstr2, int list_op);
352
353 #if defined(FEAT_RELTIME) || defined(PROTO)
354 /*
355 * Set the timeout used for syntax highlighting.
356 * Use NULL to reset, no timeout.
357 */
358 void
359 syn_set_timeout(proftime_T *tm)
360 {
361 syn_tm = tm;
362 }
363 #endif
364 349
365 /* 350 /*
366 * Start the syntax recognition for a line. This function is normally called 351 * Start the syntax recognition for a line. This function is normally called
367 * from the screen updating, once for each displayed line. 352 * from the screen updating, once for each displayed line.
368 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get 353 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get
3164 linenr_T lnum, 3149 linenr_T lnum,
3165 colnr_T col, 3150 colnr_T col,
3166 syn_time_T *st UNUSED) 3151 syn_time_T *st UNUSED)
3167 { 3152 {
3168 int r; 3153 int r;
3169 #ifdef FEAT_RELTIME
3170 int timed_out = FALSE; 3154 int timed_out = FALSE;
3171 #endif
3172 #ifdef FEAT_PROFILE 3155 #ifdef FEAT_PROFILE
3173 proftime_T pt; 3156 proftime_T pt;
3174 3157
3175 if (syn_time_on) 3158 if (syn_time_on)
3176 profile_start(&pt); 3159 profile_start(&pt);
3181 // use the NFA engine, which resulted in NFA_TOO_EXPENSIVE, and 3164 // use the NFA engine, which resulted in NFA_TOO_EXPENSIVE, and
3182 // compiling the pattern with the other engine fails. 3165 // compiling the pattern with the other engine fails.
3183 return FALSE; 3166 return FALSE;
3184 3167
3185 rmp->rmm_maxcol = syn_buf->b_p_smc; 3168 rmp->rmm_maxcol = syn_buf->b_p_smc;
3186 r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, 3169 r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, &timed_out);
3187 #ifdef FEAT_RELTIME
3188 syn_tm, &timed_out
3189 #else
3190 NULL, NULL
3191 #endif
3192 );
3193 3170
3194 #ifdef FEAT_PROFILE 3171 #ifdef FEAT_PROFILE
3195 if (syn_time_on) 3172 if (syn_time_on)
3196 { 3173 {
3197 profile_end(&pt); 3174 profile_end(&pt);