+/* Juanma Barranquero <lekktu@gmail.com> reported ~3x increased
+ bootstrap time when byte_char_debug_check is enabled; so this
+ is never turned on by --enable-checking configure option. */
+
+#ifdef MARKER_DEBUG
+
+extern int count_markers (struct buffer *) EXTERNALLY_VISIBLE;
+extern ptrdiff_t verify_bytepos (ptrdiff_t charpos) EXTERNALLY_VISIBLE;
+
+static void
+byte_char_debug_check (struct buffer *b, ptrdiff_t charpos, ptrdiff_t bytepos)
+{
+ ptrdiff_t nchars;
+
+ if (NILP (BVAR (b, enable_multibyte_characters)))
+ return;
+
+ if (bytepos > BUF_GPT_BYTE (b))
+ nchars
+ = multibyte_chars_in_text (BUF_BEG_ADDR (b),
+ BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b))
+ + multibyte_chars_in_text (BUF_GAP_END_ADDR (b),
+ bytepos - BUF_GPT_BYTE (b));
+ else
+ nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
+ bytepos - BUF_BEG_BYTE (b));
+
+ if (charpos - 1 != nchars)
+ abort ();
+}