patch 8.2.0669: MS-Windows: display in VTP is a bit slow

Problem:    MS-Windows: display in VTP is a bit slow.
Solution:   Optimize the code. (Nobuhiro Takasaki, closes #6014)
diff --git a/src/screen.c b/src/screen.c
index 845c5b2..09aa10f 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1880,6 +1880,9 @@
 screen_stop_highlight(void)
 {
     int	    do_ME = FALSE;	    // output T_ME code
+#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
+    int	    do_ME_fg, do_ME_bg;
+#endif
 
     if (screen_attr != 0
 #ifdef MSWIN
@@ -1913,16 +1916,42 @@
 #ifdef FEAT_TERMGUICOLORS
 			    p_tgc && aep->ae_u.cterm.fg_rgb != CTERMCOLOR
 				? aep->ae_u.cterm.fg_rgb != INVALCOLOR
+# ifdef FEAT_VTP
+				    ? !(do_ME_fg = TRUE) : (do_ME_fg = FALSE)
+# endif
 				:
 #endif
 				aep->ae_u.cterm.fg_color) || (
 #ifdef FEAT_TERMGUICOLORS
 			    p_tgc && aep->ae_u.cterm.bg_rgb != CTERMCOLOR
 				? aep->ae_u.cterm.bg_rgb != INVALCOLOR
+# ifdef FEAT_VTP
+				    ? !(do_ME_bg = TRUE) : (do_ME_bg = FALSE)
+# endif
 				:
 #endif
 				aep->ae_u.cterm.bg_color)))
 			do_ME = TRUE;
+#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
+		    if (use_vtp())
+		    {
+			if (do_ME_fg && do_ME_bg)
+			    do_ME = TRUE;
+
+			// FG and BG cannot be separated in T_ME, which is not
+			// efficient.
+			if (!do_ME && do_ME_fg)
+			    out_str((char_u *)"\033|39m"); // restore FG
+			if (!do_ME && do_ME_bg)
+			    out_str((char_u *)"\033|49m"); // restore BG
+		    }
+		    else
+		    {
+			// Process FG and BG at once.
+			if (!do_ME)
+			    do_ME = do_ME_fg | do_ME_bg;
+		    }
+#endif
 		}
 		else
 		{