Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: An idea for fast "last-N-lines" read



On Mar 20, 11:04pm, Sebastian Gniazdowski wrote:
}
} I read somewhere that to read "last-N-lines" it is good to memory-map
} the file. Cannot check with Zsh [...]
} - apparently because it memory-maps the file on each newline check.

Indeed, the mapfile module doesn't help much after the initial file
read because zsh has no mechanism for holding a reference to the
mapped block of memory.  It's mostly for quickly copying the entire
file into and out of regular heap.

This could, however, be made a lot better, e.g. by introducing a cache
of mapped files into mapfile.c and causing get_contents() to first use
the cache (and setpmmapfile to update it, unsetpmmapfile to erase an
entry from it) before resorting to remapping the actual file.

} I'm thinking about: $(<10<filepath) syntax

I'm not thrilled about adding new syntax for this, and anyway that
conflicts with multios semantics.

} BTW, (@f) skips trailing \n\n... That's quite problematic and there's
} probably no workaround?

In double quotes, (@f) retains empty elements, which includes making
empty elements out of trailing newlines.  However, there is no way to
get $(<file) [or $(<<<string) etc.] to retain trailing newlines, which
is most likely what's misleading you.



Messages sorted by: Reverse Date, Date, Thread, Author