diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-06-25 14:53:39 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-06-25 14:55:08 -0700 |
commit | d7c6836288c91bb639956cb8c748dd6597c55cd4 (patch) | |
tree | 687f6f257d3cb5f4bd54eb634aef2737eb9c0856 /m4 | |
parent | 349b778dde7f583a92dd1531aef3ff5c336e9aee (diff) | |
download | emacs-d7c6836288c91bb639956cb8c748dd6597c55cd4.tar.gz |
Avoid some strlen work, primarily via strnlen
* admin/merge-gnulib (GNULIB_MODULES): Add strnlen.
* lib-src/etags.c (find_entries):
* src/emacs.c (main):
* src/nsmenu.m (parseKeyEquiv:):
* src/nsterm.m (ns_xlfd_to_fontname):
* src/term.c (vfatal):
Prefer !*X to !strlen (X).
* lib-src/etags.c (pfnote, add_regex):
* lib-src/pop.c (pop_open):
* lib-src/update-game-score.c (main):
* lwlib/lwlib.c (lw_separator_p):
* src/doprnt.c (doprnt):
* src/emacs.c (main):
* src/inotify.c (inotifyevent_to_event):
* src/keyboard.c (menu_separator_name_p, parse_tool_bar_item):
* src/sysdep.c (get_current_dir_name_or_unreachable):
* src/xdisp.c (store_mode_line_string):
Use strnlen to avoid unnecessary work with strlen.
* lib-src/etags.c (Prolog_functions, prolog_pr)
(Erlang_functions, erlang_func):
Prefer ptrdiff_t to size_t when either will do.
(prolog_pr, erlang_func): New arg LASTLEN, to avoid
unnecessary strlen call. All callers changed.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lib/strnlen.c, m4/strnlen.m4: New files, copied from Gnulib.
* lwlib/lwlib.c (lw_separator_p):
* src/json.c (json_has_prefix):
Use strncmp to avoid unecessary work with strlen + memcmp.
* src/process.c (set_socket_option): Use SBYTES instead of strlen.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/gnulib-comp.m4 | 9 | ||||
-rw-r--r-- | m4/strnlen.m4 | 30 |
2 files changed, 39 insertions, 0 deletions
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index cb6dce15ccf..7e724fe3c4e 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -154,6 +154,7 @@ AC_DEFUN([gl_EARLY], # Code from module stdlib: # Code from module stpcpy: # Code from module string: + # Code from module strnlen: # Code from module strtoimax: # Code from module strtoll: # Code from module symlink: @@ -403,6 +404,12 @@ AC_DEFUN([gl_INIT], fi gl_STRING_MODULE_INDICATOR([stpcpy]) gl_HEADER_STRING_H + gl_FUNC_STRNLEN + if test $HAVE_DECL_STRNLEN = 0 || test $REPLACE_STRNLEN = 1; then + AC_LIBOBJ([strnlen]) + gl_PREREQ_STRNLEN + fi + gl_STRING_MODULE_INDICATOR([strnlen]) gl_FUNC_STRTOIMAX if test $HAVE_DECL_STRTOIMAX = 0 || test $REPLACE_STRTOIMAX = 1; then AC_LIBOBJ([strtoimax]) @@ -1003,6 +1010,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/str-two-way.h lib/strftime.h lib/string.in.h + lib/strnlen.c lib/strtoimax.c lib/strtol.c lib/strtoll.c @@ -1131,6 +1139,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/stdlib_h.m4 m4/stpcpy.m4 m4/string_h.m4 + m4/strnlen.m4 m4/strtoimax.m4 m4/strtoll.m4 m4/symlink.m4 diff --git a/m4/strnlen.m4 b/m4/strnlen.m4 new file mode 100644 index 00000000000..c283c3ece9f --- /dev/null +++ b/m4/strnlen.m4 @@ -0,0 +1,30 @@ +# strnlen.m4 serial 13 +dnl Copyright (C) 2002-2003, 2005-2007, 2009-2019 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRNLEN], +[ + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + + dnl Persuade glibc <string.h> to declare strnlen(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_DECLS_ONCE([strnlen]) + if test $ac_cv_have_decl_strnlen = no; then + HAVE_DECL_STRNLEN=0 + else + m4_pushdef([AC_LIBOBJ], [:]) + dnl Note: AC_FUNC_STRNLEN does AC_LIBOBJ([strnlen]). + AC_FUNC_STRNLEN + m4_popdef([AC_LIBOBJ]) + if test $ac_cv_func_strnlen_working = no; then + REPLACE_STRNLEN=1 + fi + fi +]) + +# Prerequisites of lib/strnlen.c. +AC_DEFUN([gl_PREREQ_STRNLEN], [:]) |