Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: An idea for fast "last-N-lines" read
- X-seq: zsh-workers 40884
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Sebastian Gniazdowski <psprint3@xxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: An idea for fast "last-N-lines" read
- Date: Wed, 22 Mar 2017 20:53:04 -0700
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=brasslantern-com.20150623.gappssmtp.com
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=co6BpArrvOeib/zbxrTp4EiW/NdxtcAlwPSVeM0YFPg=; b=fokasxVtndOKwV6mxsMIudqzn4RXj68cous+svUPCdwSCvHK2Ccjq5nYzGxMJa0S81 fIDlx8nm4nJzx7cmCJH/5bU6BMh+xCwIz+2BjRhB4Ak20MUOSnrs2XOBPJRTNpCPDb9O nA9xfIAzjZSdxTa1z+/U0sCWt/dYr5GY0FiJrUtDai/Y4NMi3YITYN9hCW710w6wq+Df vMHgx4jBj4zBy2HQWMTs69M/7CTZRUBYzcja6geacgpM2Ep+GzhQhA0PmtNQjLfzCWFD pvkH+jXrciS0V3UItRZvQBiMIzhFbumY7f+rGiBwblTiQyNmGrWUY2R5c2SvZZPIiNh9 J9XA==
- In-reply-to: <1490076282.321781.918060736.22D2C432@webmail.messagingengine.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1490076282.321781.918060736.22D2C432@webmail.messagingengine.com>
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