bug-gawk
[Top][All Lists]
Advanced

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

Re: How to substitute in a string for the first n matches?


From: Wolfgang Laun
Subject: Re: How to substitute in a string for the first n matches?
Date: Mon, 29 Mar 2021 16:52:05 +0200

Peng,
if you have a task that requires the frequent handling of long string with
functions like these, (g)awk may or may not be the right tool.
(g)awk hides implementation details - as I said, you don't see the storage.
Hence, it is useless to think in terms of string copying if you see a
statement like
   stra = strb strc
First, the implementation doesn't need to store these strings in the C
manner, i.e. bytes followed by a zero byte. The second reason is that - if
string copying is used - it'll happen in a way that makes a string copy
almost like a single instruction, running the actual loop in microcode.

-W






On Mon, 29 Mar 2021 at 16:44, Peng Yu <pengyu.ut@gmail.com> wrote:

> On Mon, Mar 29, 2021 at 9:38 AM <arnold@skeeve.com> wrote:
> >
> > Unless your string is many megabytes long, you won't notice the time
> > issue.
>
> I don't want to assume how small the input is.
>
> > There are other options, for example using patsplit and then putting
> > the string back together as desired.
>
> This incurs extra copying.
>
> > In any case, gensub isn't going to be extended to allow arbitrary
> > ranges and/or lists of occurrences to substitute.
>
> Why it can not be extended? After all, the extension won't break any
> existing function call convention.
>
> > Gawk provides
> > the basic building blocks as built-in functionality; more specific
> > use cases should be dealt with in user defined functions.
>
> The problem is that no current functionality in awk support efficient
> implementation of this feature.
>
> --
> Regards,
> Peng
>
>

-- 
Wolfgang Laun


reply via email to

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