[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add new lisp function length= with bytecode support

From: Gdobbins
Subject: [PATCH] Add new lisp function length= with bytecode support
Date: Sun, 26 Feb 2017 17:04:26 -0500

The attatched patch has two commits. The first implements a new lisp function, length=, which acts the same as the function of the same name from the Common Lisp package Alexandria. Namely it compares the length of sequences with numbers. The second modifies the byte interpreter to treat = the same as length=, and the byte compiler to generate the appropriate code. By greping the Emacs repo's *.el files and comparing to *.elc files after compiling with the compiler-macro in the second commit of this patch, I estimate 14% of all calls to length in Emacs are then simply compared via =. This makes length= quite useful, and since a large amount of linked list traversal can be avoided, potentially more efficient.

Part of that efficiency comes from modifying the byte interpreter, the downside of which is the loss of some type checking in calls to equal. The type checking is therefore done in the byte code itself if byte-compile-delete-errors is null. For this reason I have changed that var to be t by default and changed one of its uses to rely instead on byte-compile-warnings. Incidentally some of the MELPA packages I have installed are (perhaps improperly) globally setting byte-compile-delete-errors to t, resulting in all of my installed packages to be compiled with that setting.

If it is decided that byte-compile-delete-errors should not be changed, then I don't think the other changes in the second commit are worth while unless a separate option which allows the change is used instead. Otherwise the resulting byte code for = "" be larger and calls to it would be slower, and = is used about 10 times more often than length= would be in the Emacs repo.

-- Graham Dobbins

Attachment: length=.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]