emacs-devel
[Top][All Lists]
Advanced

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

Re: empty-directory predicate, native implementation


From: Arthur Miller
Subject: Re: empty-directory predicate, native implementation
Date: Mon, 19 Oct 2020 16:01:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Michael Albinus <michael.albinus@gmx.de> writes:

> Arthur Miller <arthur.miller@live.com> writes:
>
> Hi Arthur,
>
>>> What's wrong using FIXNATP and XFIXNAT everywhere?
>>
>> If we return nil for 0 count, then it make sense to return nil for
>> negative count too?
>
> *Any* non-nil COUNT, which is not a natural number, is handled as it
> were nil. That's what my proposal for the docstring tries to say ("If
> COUNT is a natural number ...").
Yes, that is how I interpreted it; just wanted to confirm.

>> XFIXNAT will turn it negative num into some big int.
>> I thought first it is fine, but after second thought I don't think it is
>> best thing to do.
>>
>> if (FIXNUMP(return_count))
>>     {
>>       last = XFIXNUM(return_count);
>>
>>       if (last < 1)
>>         return Qnil;
>>     }
>>
>> This works better.
>
> But if you use FIXNATP instead of FIXNUMP, there's no problem at all.
I tryed, but it discards negative numbers - from lisp.h:

INLINE bool
FIXNATP (Lisp_Object x)
{
  return FIXNUMP (x) && 0 <= XFIXNUM (x);
}

This discards negative numbers, which then leaves last = 0, which
results later in all files returned. Either I have to add another test
or use FIXNUM. Or do I missinterpret the code?

With fixnum negative numbers are catched unless they are bignumbers.

FIXNATP uses under the hood FIXNUMP, so check for FIXNUMP is cheaper too.

>>>> --- a/lisp/net/tramp-adb.el
>>>> +++ b/lisp/net/tramp-adb.el
>>>> @@ -312,7 +312,7 @@ tramp-adb-handle-directory-files-and-attributes
>>>>        (copy-tree
>>>>         (with-tramp-file-property
>>>>       v localname (format "directory-files-and-attributes-%s-%s-%s-%s"
>>>> -                         full match id-format nosort)
>>>> +                         full match id-format nosort count)
>> I did that first, but then decided to skip count in format and forgot
>> to delete the count from the argument list. I didn't know how format was
>> used so I didn't want to mess with it; but if it is only for the name,
>> then it is maybe useful?
>
> Well, the name is used for caches. If we want to use the cache also for
> a non-nil COUNT, we must use it also for the cache entry.
Yes, I will add the count to format.

>>>> diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
>>>> index 6d44ad23ad..a99af70196 100644
>>>> --- a/lisp/net/tramp.el
>>>> +++ b/lisp/net/tramp.el
>>>> +(defun tramp-handle-directory-files (directory &optional full match
>>>> +                                               nosort count)
>>>
>>> This fits into one line (80 chars).
>> It is 81 chars so Emacs breaks the line. I can call it num, saves 2 chars.
>
> It's not important. But in my Emacs, the closing parenthesis is at
> position 80, IIRC :-)
Ha :-) Mine was 81. Emacs ways are strange sometimes. Anyway, I changed
to 'num' - 2 chars off! :D



reply via email to

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