aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
authorNickolas Lloyd2017-02-01 22:31:55 -0500
committerNickolas Lloyd2017-02-01 22:31:55 -0500
commit9a15b5509abb49a11c97c1101ad216f4ef258368 (patch)
tree7311337d92833cb8f233eaa696a967a15a306a80 /src/fns.c
parent5d8f2548ceaa5a0b33c08a39f1d6c11071ec63aa (diff)
parent70d36dda26465b43c1a63e8e13153e070af86456 (diff)
downloademacs-nick.lloyd-bytecode-jit.tar.gz
emacs-nick.lloyd-bytecode-jit.zip
Merge branch 'master' into nick.lloyd-bytecode-jitnick.lloyd-bytecode-jit
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c99
1 files changed, 32 insertions, 67 deletions
diff --git a/src/fns.c b/src/fns.c
index 9eabc1414f4..ac7c1f265a4 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -84,22 +84,6 @@ See Info node `(elisp)Random Numbers' for more details. */)
84 return make_number (val); 84 return make_number (val);
85} 85}
86 86
87/* Heuristic on how many iterations of a tight loop can be safely done
88 before it's time to do a quit. This must be a power of 2. It
89 is nice but not necessary for it to equal USHRT_MAX + 1. */
90enum { QUIT_COUNT_HEURISTIC = 1 << 16 };
91
92/* Process a quit, but do it only rarely, for efficiency. "Rarely"
93 means once per QUIT_COUNT_HEURISTIC or per USHRT_MAX + 1 times,
94 whichever is smaller. Use *QUIT_COUNT to count this. */
95
96static void
97rarely_quit (unsigned short int *quit_count)
98{
99 if (! (++*quit_count & (QUIT_COUNT_HEURISTIC - 1)))
100 maybe_quit ();
101}
102
103/* Random data-structure functions. */ 87/* Random data-structure functions. */
104 88
105DEFUN ("length", Flength, Slength, 1, 1, 0, 89DEFUN ("length", Flength, Slength, 1, 1, 0,
@@ -1359,20 +1343,17 @@ DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0,
1359 (Lisp_Object n, Lisp_Object list) 1343 (Lisp_Object n, Lisp_Object list)
1360{ 1344{
1361 CHECK_NUMBER (n); 1345 CHECK_NUMBER (n);
1362 EMACS_INT num = XINT (n);
1363 Lisp_Object tail = list; 1346 Lisp_Object tail = list;
1364 immediate_quit = true; 1347 for (EMACS_INT num = XINT (n); 0 < num; num--)
1365 for (EMACS_INT i = 0; i < num; i++)
1366 { 1348 {
1367 if (! CONSP (tail)) 1349 if (! CONSP (tail))
1368 { 1350 {
1369 immediate_quit = false;
1370 CHECK_LIST_END (tail, list); 1351 CHECK_LIST_END (tail, list);
1371 return Qnil; 1352 return Qnil;
1372 } 1353 }
1373 tail = XCDR (tail); 1354 tail = XCDR (tail);
1355 rarely_quit (num);
1374 } 1356 }
1375 immediate_quit = false;
1376 return tail; 1357 return tail;
1377} 1358}
1378 1359
@@ -1408,7 +1389,7 @@ The value is actually the tail of LIST whose car is ELT. */)
1408 { 1389 {
1409 if (! NILP (Fequal (elt, XCAR (tail)))) 1390 if (! NILP (Fequal (elt, XCAR (tail))))
1410 return tail; 1391 return tail;
1411 rarely_quit (&quit_count); 1392 rarely_quit (++quit_count);
1412 } 1393 }
1413 CHECK_LIST_END (tail, list); 1394 CHECK_LIST_END (tail, list);
1414 return Qnil; 1395 return Qnil;
@@ -1419,17 +1400,14 @@ DEFUN ("memq", Fmemq, Smemq, 2, 2, 0,
1419The value is actually the tail of LIST whose car is ELT. */) 1400The value is actually the tail of LIST whose car is ELT. */)
1420 (Lisp_Object elt, Lisp_Object list) 1401 (Lisp_Object elt, Lisp_Object list)
1421{ 1402{
1422 immediate_quit = true; 1403 unsigned short int quit_count = 0;
1423 Lisp_Object tail; 1404 Lisp_Object tail;
1424 for (tail = list; CONSP (tail); tail = XCDR (tail)) 1405 for (tail = list; CONSP (tail); tail = XCDR (tail))
1425 { 1406 {
1426 if (EQ (XCAR (tail), elt)) 1407 if (EQ (XCAR (tail), elt))
1427 { 1408 return tail;
1428 immediate_quit = false; 1409 rarely_quit (++quit_count);
1429 return tail;
1430 }
1431 } 1410 }
1432 immediate_quit = false;
1433 CHECK_LIST_END (tail, list); 1411 CHECK_LIST_END (tail, list);
1434 return Qnil; 1412 return Qnil;
1435} 1413}
@@ -1442,18 +1420,15 @@ The value is actually the tail of LIST whose car is ELT. */)
1442 if (!FLOATP (elt)) 1420 if (!FLOATP (elt))
1443 return Fmemq (elt, list); 1421 return Fmemq (elt, list);
1444 1422
1445 immediate_quit = true; 1423 unsigned short int quit_count = 0;
1446 Lisp_Object tail; 1424 Lisp_Object tail;
1447 for (tail = list; CONSP (tail); tail = XCDR (tail)) 1425 for (tail = list; CONSP (tail); tail = XCDR (tail))
1448 { 1426 {
1449 Lisp_Object tem = XCAR (tail); 1427 Lisp_Object tem = XCAR (tail);
1450 if (FLOATP (tem) && internal_equal (elt, tem, 0, 0, Qnil)) 1428 if (FLOATP (tem) && internal_equal (elt, tem, 0, 0, Qnil))
1451 { 1429 return tail;
1452 immediate_quit = false; 1430 rarely_quit (++quit_count);
1453 return tail;
1454 }
1455 } 1431 }
1456 immediate_quit = false;
1457 CHECK_LIST_END (tail, list); 1432 CHECK_LIST_END (tail, list);
1458 return Qnil; 1433 return Qnil;
1459} 1434}
@@ -1464,15 +1439,14 @@ The value is actually the first element of LIST whose car is KEY.
1464Elements of LIST that are not conses are ignored. */) 1439Elements of LIST that are not conses are ignored. */)
1465 (Lisp_Object key, Lisp_Object list) 1440 (Lisp_Object key, Lisp_Object list)
1466{ 1441{
1467 immediate_quit = true; 1442 unsigned short int quit_count = 0;
1468 Lisp_Object tail; 1443 Lisp_Object tail;
1469 for (tail = list; CONSP (tail); tail = XCDR (tail)) 1444 for (tail = list; CONSP (tail); tail = XCDR (tail))
1470 if (CONSP (XCAR (tail)) && EQ (XCAR (XCAR (tail)), key)) 1445 {
1471 { 1446 if (CONSP (XCAR (tail)) && EQ (XCAR (XCAR (tail)), key))
1472 immediate_quit = false;
1473 return XCAR (tail); 1447 return XCAR (tail);
1474 } 1448 rarely_quit (++quit_count);
1475 immediate_quit = false; 1449 }
1476 CHECK_LIST_END (tail, list); 1450 CHECK_LIST_END (tail, list);
1477 return Qnil; 1451 return Qnil;
1478} 1452}
@@ -1502,7 +1476,7 @@ The value is actually the first element of LIST whose car equals KEY. */)
1502 if (CONSP (car) 1476 if (CONSP (car)
1503 && (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key)))) 1477 && (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key))))
1504 return car; 1478 return car;
1505 rarely_quit (&quit_count); 1479 rarely_quit (++quit_count);
1506 } 1480 }
1507 CHECK_LIST_END (tail, list); 1481 CHECK_LIST_END (tail, list);
1508 return Qnil; 1482 return Qnil;
@@ -1529,15 +1503,14 @@ DEFUN ("rassq", Frassq, Srassq, 2, 2, 0,
1529The value is actually the first element of LIST whose cdr is KEY. */) 1503The value is actually the first element of LIST whose cdr is KEY. */)
1530 (Lisp_Object key, Lisp_Object list) 1504 (Lisp_Object key, Lisp_Object list)
1531{ 1505{
1532 immediate_quit = true; 1506 unsigned short int quit_count = 0;
1533 Lisp_Object tail; 1507 Lisp_Object tail;
1534 for (tail = list; CONSP (tail); tail = XCDR (tail)) 1508 for (tail = list; CONSP (tail); tail = XCDR (tail))
1535 if (CONSP (XCAR (tail)) && EQ (XCDR (XCAR (tail)), key)) 1509 {
1536 { 1510 if (CONSP (XCAR (tail)) && EQ (XCDR (XCAR (tail)), key))
1537 immediate_quit = false;
1538 return XCAR (tail); 1511 return XCAR (tail);
1539 } 1512 rarely_quit (++quit_count);
1540 immediate_quit = false; 1513 }
1541 CHECK_LIST_END (tail, list); 1514 CHECK_LIST_END (tail, list);
1542 return Qnil; 1515 return Qnil;
1543} 1516}
@@ -1555,7 +1528,7 @@ The value is actually the first element of LIST whose cdr equals KEY. */)
1555 if (CONSP (car) 1528 if (CONSP (car)
1556 && (EQ (XCDR (car), key) || !NILP (Fequal (XCDR (car), key)))) 1529 && (EQ (XCDR (car), key) || !NILP (Fequal (XCDR (car), key))))
1557 return car; 1530 return car;
1558 rarely_quit (&quit_count); 1531 rarely_quit (++quit_count);
1559 } 1532 }
1560 CHECK_LIST_END (tail, list); 1533 CHECK_LIST_END (tail, list);
1561 return Qnil; 1534 return Qnil;
@@ -1711,7 +1684,7 @@ changing the value of a sequence `foo'. */)
1711 } 1684 }
1712 else 1685 else
1713 prev = tail; 1686 prev = tail;
1714 rarely_quit (&quit_count); 1687 rarely_quit (++quit_count);
1715 } 1688 }
1716 CHECK_LIST_END (tail, seq); 1689 CHECK_LIST_END (tail, seq);
1717 } 1690 }
@@ -1736,10 +1709,10 @@ This function may destructively modify SEQ to produce the value. */)
1736 1709
1737 for (prev = Qnil, tail = seq; CONSP (tail); tail = next) 1710 for (prev = Qnil, tail = seq; CONSP (tail); tail = next)
1738 { 1711 {
1739 rarely_quit (&quit_count);
1740 next = XCDR (tail); 1712 next = XCDR (tail);
1741 Fsetcdr (tail, prev); 1713 Fsetcdr (tail, prev);
1742 prev = tail; 1714 prev = tail;
1715 rarely_quit (++quit_count);
1743 } 1716 }
1744 CHECK_LIST_END (tail, seq); 1717 CHECK_LIST_END (tail, seq);
1745 seq = prev; 1718 seq = prev;
@@ -1785,8 +1758,8 @@ See also the function `nreverse', which is used more often. */)
1785 unsigned short int quit_count = 0; 1758 unsigned short int quit_count = 0;
1786 for (new = Qnil; CONSP (seq); seq = XCDR (seq)) 1759 for (new = Qnil; CONSP (seq); seq = XCDR (seq))
1787 { 1760 {
1788 rarely_quit (&quit_count);
1789 new = Fcons (XCAR (seq), new); 1761 new = Fcons (XCAR (seq), new);
1762 rarely_quit (++quit_count);
1790 } 1763 }
1791 CHECK_LIST_END (seq, seq); 1764 CHECK_LIST_END (seq, seq);
1792 } 1765 }
@@ -2077,21 +2050,20 @@ use `(setq x (plist-put x prop val))' to be sure to use the new value.
2077The PLIST is modified by side effects. */) 2050The PLIST is modified by side effects. */)
2078 (Lisp_Object plist, Lisp_Object prop, Lisp_Object val) 2051 (Lisp_Object plist, Lisp_Object prop, Lisp_Object val)
2079{ 2052{
2080 immediate_quit = true; 2053 unsigned short int quit_count = 0;
2081 Lisp_Object prev = Qnil; 2054 Lisp_Object prev = Qnil;
2082 for (Lisp_Object tail = plist; CONSP (tail) && CONSP (XCDR (tail)); 2055 for (Lisp_Object tail = plist; CONSP (tail) && CONSP (XCDR (tail));
2083 tail = XCDR (XCDR (tail))) 2056 tail = XCDR (XCDR (tail)))
2084 { 2057 {
2085 if (EQ (prop, XCAR (tail))) 2058 if (EQ (prop, XCAR (tail)))
2086 { 2059 {
2087 immediate_quit = false;
2088 Fsetcar (XCDR (tail), val); 2060 Fsetcar (XCDR (tail), val);
2089 return plist; 2061 return plist;
2090 } 2062 }
2091 2063
2092 prev = tail; 2064 prev = tail;
2065 rarely_quit (++quit_count);
2093 } 2066 }
2094 immediate_quit = false;
2095 Lisp_Object newcell 2067 Lisp_Object newcell
2096 = Fcons (prop, Fcons (val, NILP (prev) ? plist : XCDR (XCDR (prev)))); 2068 = Fcons (prop, Fcons (val, NILP (prev) ? plist : XCDR (XCDR (prev))));
2097 if (NILP (prev)) 2069 if (NILP (prev))
@@ -2128,7 +2100,7 @@ one of the properties on the list. */)
2128 { 2100 {
2129 if (! NILP (Fequal (prop, XCAR (tail)))) 2101 if (! NILP (Fequal (prop, XCAR (tail))))
2130 return XCAR (XCDR (tail)); 2102 return XCAR (XCDR (tail));
2131 rarely_quit (&quit_count); 2103 rarely_quit (++quit_count);
2132 } 2104 }
2133 2105
2134 CHECK_LIST_END (tail, prop); 2106 CHECK_LIST_END (tail, prop);
@@ -2158,7 +2130,7 @@ The PLIST is modified by side effects. */)
2158 } 2130 }
2159 2131
2160 prev = tail; 2132 prev = tail;
2161 rarely_quit (&quit_count); 2133 rarely_quit (++quit_count);
2162 } 2134 }
2163 Lisp_Object newcell = list2 (prop, val); 2135 Lisp_Object newcell = list2 (prop, val);
2164 if (NILP (prev)) 2136 if (NILP (prev))
@@ -2238,7 +2210,7 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, int depth, bool props,
2238 2210
2239 unsigned short int quit_count = 0; 2211 unsigned short int quit_count = 0;
2240 tail_recurse: 2212 tail_recurse:
2241 rarely_quit (&quit_count); 2213 rarely_quit (++quit_count);
2242 if (EQ (o1, o2)) 2214 if (EQ (o1, o2))
2243 return 1; 2215 return 1;
2244 if (XTYPE (o1) != XTYPE (o2)) 2216 if (XTYPE (o1) != XTYPE (o2))
@@ -2442,18 +2414,15 @@ usage: (nconc &rest LISTS) */)
2442 2414
2443 CHECK_CONS (tem); 2415 CHECK_CONS (tem);
2444 2416
2445 immediate_quit = true;
2446 Lisp_Object tail; 2417 Lisp_Object tail;
2447 do 2418 do
2448 { 2419 {
2449 tail = tem; 2420 tail = tem;
2450 tem = XCDR (tail); 2421 tem = XCDR (tail);
2422 rarely_quit (++quit_count);
2451 } 2423 }
2452 while (CONSP (tem)); 2424 while (CONSP (tem));
2453 2425
2454 immediate_quit = false;
2455 rarely_quit (&quit_count);
2456
2457 tem = args[argnum + 1]; 2426 tem = args[argnum + 1];
2458 Fsetcdr (tail, tem); 2427 Fsetcdr (tail, tem);
2459 if (NILP (tem)) 2428 if (NILP (tem))
@@ -2874,13 +2843,13 @@ property and a property with the value nil.
2874The value is actually the tail of PLIST whose car is PROP. */) 2843The value is actually the tail of PLIST whose car is PROP. */)
2875 (Lisp_Object plist, Lisp_Object prop) 2844 (Lisp_Object plist, Lisp_Object prop)
2876{ 2845{
2877 immediate_quit = true; 2846 unsigned short int quit_count = 0;
2878 while (CONSP (plist) && !EQ (XCAR (plist), prop)) 2847 while (CONSP (plist) && !EQ (XCAR (plist), prop))
2879 { 2848 {
2880 plist = XCDR (plist); 2849 plist = XCDR (plist);
2881 plist = CDR (plist); 2850 plist = CDR (plist);
2851 rarely_quit (++quit_count);
2882 } 2852 }
2883 immediate_quit = false;
2884 return plist; 2853 return plist;
2885} 2854}
2886 2855
@@ -5120,10 +5089,6 @@ On some platforms, file selection dialogs are also enabled if this is
5120non-nil. */); 5089non-nil. */);
5121 use_dialog_box = 1; 5090 use_dialog_box = 1;
5122 5091
5123 DEFVAR_LISP("watch-object", Vwatch_object,
5124 doc: /* Symbol to watch. */);
5125 Vwatch_object = Qnil;
5126
5127 DEFVAR_BOOL ("use-file-dialog", use_file_dialog, 5092 DEFVAR_BOOL ("use-file-dialog", use_file_dialog,
5128 doc: /* Non-nil means mouse commands use a file dialog to ask for files. 5093 doc: /* Non-nil means mouse commands use a file dialog to ask for files.
5129This applies to commands from menus and tool bar buttons even when 5094This applies to commands from menus and tool bar buttons even when