[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/m-buffer a8d5ce9755 050/115: Performance enhancements t
From: |
ELPA Syncer |
Subject: |
[elpa] externals/m-buffer a8d5ce9755 050/115: Performance enhancements to subtract. |
Date: |
Tue, 19 Jul 2022 15:58:48 -0400 (EDT) |
branch: externals/m-buffer
commit a8d5ce975556101992c486b257f650f90a7fcee9
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>
Performance enhancements to subtract.
---
m-buffer.el | 54 ++++++++++++++++++++++++++++++++++-----------------
test/m-buffer-test.el | 25 +++++++++++++++++++++++-
2 files changed, 60 insertions(+), 19 deletions(-)
diff --git a/m-buffer.el b/m-buffer.el
index 7ca2dafab6..a94e557426 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -39,8 +39,8 @@
;;
;; This library is early release at the moment. I write it become I got fed up
;; with writing (while (re-search-forward) do-stuff) forms. I found that it
-;; considerably simplified writing `linked-buffer'. I make no guarantees about
-;; the API at the moment.
+;; considerably simplified writing `linked-buffer'. The API is beginning to
+;; stablize now and should not undergo major changes.
;;; Code:
(require 'dash)
@@ -187,12 +187,12 @@ This is an internal function."
(if (plist-member pargs :case-fold-search)
(plist-get pargs :case-fold-search)
:default))
-
+
;; numeric
(numeric
(plist-get pargs :numeric)))
-
+
(list buffer regexp begin end post-match widen cfs numeric)))
(defun m-buffer-ensure-match (&rest match)
@@ -302,9 +302,13 @@ function. See `m-buffer-nil-marker' for details."
Matches are equal if they match the same region; subgroups are
ignored."
;; can we speed this up by not making subsets?
- (equal
- (-take 2 m)
- (-take 2 n)))
+ (and
+ (equal
+ (car m)
+ (car n))
+ (equal
+ (cadr m)
+ (cadr n))))
(defun m-buffer-match-subtract (m n)
"Remove from M any matches in N.
@@ -324,18 +328,32 @@ runs faster but has some restrictions."
"Remove from M any matches in N.
Both M and N must be fully ordered, and any element in N must be
in M."
- ;; copy n
- (let ((n-eaten n))
- (-remove
- (lambda (o)
- ;; check the first element of n
- (when (m-buffer-match-equal
+ (if n
+ (let ((n-eaten n))
+ (-remove
+ (lambda (o)
+ (cond
+ ;; we have a match so throw away the first element of n-eaten
+ ;; which we won't need again.
+ ((m-buffer-match-equal
(car n-eaten) o)
- ;; we have a match so throw away the first element of n-eaten
- ;; which we won't need again.
- (setq n-eaten (-drop 1 n-eaten))
- t))
- m)))
+ (progn
+ (setq n-eaten (-drop 1 n-eaten))
+ t))
+ ;; we should discard also if n-eaten 1 is less than o because, both
+ ;; are sorted, so we will never match
+ ((<
+ ;; first half of the first match in n-eaten
+ (caar n-eaten)
+ ;; first half of match
+ (car o))
+ (progn
+ (setq n-eaten (-drop 1 n-eaten))
+ t))))
+ m))
+ m))
+
+
;; marker/position utility functions
(defun m-buffer-nil-marker (markers)
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 0dd7b5aa86..3253ce2505 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -321,7 +321,21 @@
(m-buffer-match
(current-buffer) "sentence")))))))
-(ert-deftest exact-substract ()
+(ert-deftest exact-subtract ()
+ (should
+ (equal
+ '((1 1)(2 2)(3 3))
+ (m-buffer-match-exact-subtract
+ '((0 0) (1 1) (2 2) (3 3) (4 4))
+ '((0 0) (4 4)))))
+
+ (should
+ (equal
+ '((1 1)(2 2)(3 3))
+ (m-buffer-match-exact-subtract
+ '((0 0) (1 1) (2 2) (3 3) (4 4))
+ '((-1 -1) (4 4)))))
+
(should
(equal
'((1 6) (17 23) (34 39))
@@ -334,5 +348,14 @@
(m-buffer-match
(current-buffer) "sentence")))))))
+(ert-deftest exact-subtract-with-nil ()
+ (should
+ (equal
+ '((1 1))
+ (m-buffer-match-exact-subtract
+ '((1 1))
+ nil))))
+
+
;;; m-buffer-test.el ends here
- [elpa] externals/m-buffer 22d6b0d640 012/115: Beginning has become begin. Widen option added. New line matching functions., (continued)
- [elpa] externals/m-buffer 22d6b0d640 012/115: Beginning has become begin. Widen option added. New line matching functions., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer c65b7b20c0 014/115: match-data-1 was failing on final match due to off-by-one error., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 1cc4d8cffb 015/115: Added functions: m-buffer-marker-tree-to-pos, m-buffer-match-nth-group., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 27380daef5 018/115: Functions to add overlays and properties to buffers., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 41384768bc 024/115: Merge pull request #1 from syohex/fix-typo, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer e4ec4daa87 027/115: replace-match now returns marker to the end of the replacements., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 41ca2908a3 032/115: Added documentation for four functions., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer b7c9738f31 037/115: Update readme for 0.4 release., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 93f64edf1b 046/115: Added support for case-fold-search, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 761ba8e4b7 049/115: Equals and subtract functionality added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer a8d5ce9755 050/115: Performance enhancements to subtract.,
ELPA Syncer <=
- [elpa] externals/m-buffer fd9d92a0aa 052/115: Added marmalade for noflet., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 8d351bb5fd 054/115: m-buffer-with-current-marker added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer d6701d8ce2 044/115: Remove extraneous dash dependency to dash., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 25c2b37969 071/115: m-buffer-point renamed to m-buffer-at-point., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 5166d21792 081/115: Lentic documentation for m-buffer.el., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 22ef3ac985 005/115: Emacs 24 only!, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer cbd9d12b3d 023/115: Functions for colourizing text. Improved documentation., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 6e8e29e12d 022/115: Fix some typos, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 05846a92bc 035/115: Removed "-data" from m-buffer-match-data., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 11990bba65 045/115: Version 0.5 release., ELPA Syncer, 2022/07/19