zsh-workers
 help / color / mirror / code / Atom feed
* Append to array via (P) flag
@ 2017-03-18 15:13 Sebastian Gniazdowski
  2017-03-18 17:07 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-18 15:13 UTC (permalink / raw)
  To: zsh-workers

Hello,
I've written simple text editor in ZUI and the supported number of lines
is 1000. With 5.3.1-dev-0 it is 6000, but the code needs special
construct. Problem is in API function that does:

__output=( "${(P@)__var_name}" "New data" )
: ${(PA)__var_name::=${__output[@]}}

There is no append-syntax recognized by (P), so no easy way to trigger
optimizations. Maybe this can be added? Parameter like __var_name could
be set to:
- reply[]
- reply[-]
- reply[,]

So doing e.g. reply[,]=( "New data" ) would work like reply+=( "New
data" )

Maybe it's best to discover something really special so there is no
impression that shell syntax changes. Or opposite, use e.g. comma,
because it is already used inside [].

-- 
  Sebastian Gniazdowski
  psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Append to array via (P) flag
  2017-03-18 15:13 Append to array via (P) flag Sebastian Gniazdowski
@ 2017-03-18 17:07 ` Bart Schaefer
  2017-03-18 17:32   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2017-03-18 17:07 UTC (permalink / raw)
  To: zsh-workers

On Mar 18,  8:13am, Sebastian Gniazdowski wrote:
}
} Problem is in API function that does:
} 
} __output=( "${(P@)__var_name}" "New data" )
} : ${(PA)__var_name::=${__output[@]}}

You can already do this, you just need to know the length of the
array so that you can index past the end of it:

    __output=("New Data" "Like this")
    __append="${__var_name}[${(P)#__var_name}+1]"
    : ${(PA)__append::=${(@)__output}}

With extendedglob set I'm pretty sure this will work in all cases:

    __append="${__var_name}[(r)(^*)]"
    : ${(PA)__append::=${(@)__output}}

The pattern (^*) will never match, ${(P)__append} will always be off
the end of the array, and there you go.  But that might actually be
less efficient than the extra ${(P)#__var_name}.

You can also insert stuff into the middle of an array by using a
reverse-ordered subscript, e.g. to shove the new values in between the
fifth and sixth elements:

    __insert="${__var_name}[6,5]"
    : ${(PA)__insert::=${(@)__output}}

Out of idle curiousity, why would you write a new text editor when
you can already use "vared" on a memory-mapped file?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Append to array via (P) flag
  2017-03-18 17:07 ` Bart Schaefer
@ 2017-03-18 17:32   ` Sebastian Gniazdowski
  2017-03-18 21:50     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-18 17:32 UTC (permalink / raw)
  To: zsh-workers

On Sat, Mar 18, 2017, at 10:07 AM, Bart Schaefer wrote:
> On Mar 18,  8:13am, Sebastian Gniazdowski wrote:
> }
> } Problem is in API function that does:
> } 
> } __output=( "${(P@)__var_name}" "New data" )
> } : ${(PA)__var_name::=${__output[@]}}
> 
> You can already do this, you just need to know the length of the
> array so that you can index past the end of it:
> 
>     __output=("New Data" "Like this")
>     __append="${__var_name}[${(P)#__var_name}+1]"
>     : ${(PA)__append::=${(@)__output}}

Ok, I will have to rewrite parts of code to use that. Ran callgrind to
see the bottleneck when utilizing 5.3.1-dev-0 optimizations via the
"special construct" I mentioned:

196,685,461  arrlen [/usr/local/bin/zsh-5.3.1-dev-0_O2]
179,629,793  itype_end [/usr/local/bin/zsh-5.3.1-dev-0_O2]
159,548,348  stringsubst [/usr/local/bin/zsh-5.3.1-dev-0_O2]
 85,139,775  paramsubst [/usr/local/bin/zsh-5.3.1-dev-0_O2]
 84,031,867  szone_free_definite_size
 [/usr/lib/system/libsystem_malloc.dylib]
 61,686,940  hasbraces [/usr/local/bin/zsh-5.3.1-dev-0_O2]
 58,934,416  remnulargs [/usr/local/bin/zsh-5.3.1-dev-0_O2]

Not that expected, the array of 7000 lines at final, to induce arrlen to
top. However, that's only 9% (196685461.0 / 2171855290 * 100). Wonder
what's itype_end and what stringsubst is doing.

> Out of idle curiousity, why would you write a new text editor when
> you can already use "vared" on a memory-mapped file?

For e.g. devops, to be able to use text-area in some e.g. deploy tool.
To have some buttons like "run", "restart", and a 100-lines config file
that needs just e.g. IP address alterations. The editor is just 58 lines
of code, I hope people will understand how much cheap textual-UI they
can get. vared doesn't integrate with buttons, list-boxes, etc.

Here's the editor, looks quite scary hehe:
https://asciinema.org/a/107800
-- 
  Sebastian Gniazdowski
  psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Append to array via (P) flag
  2017-03-18 17:32   ` Sebastian Gniazdowski
@ 2017-03-18 21:50     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2017-03-18 21:50 UTC (permalink / raw)
  To: zsh-workers

On Mar 18, 10:32am, Sebastian Gniazdowski wrote:
}
} 179,629,793  itype_end [/usr/local/bin/zsh-5.3.1-dev-0_O2]
} 
} Wonder what's itype_end and what stringsubst is doing.

itype_end() examines a string to skip over the leading part that looks
like a valid identifier ("i"dentifier"type").  E.g. skipping over the
variable name to find whatever operators follow it.  It's actually used
for several different kinds of identifiers.  See comment in utils.c.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-18 21:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18 15:13 Append to array via (P) flag Sebastian Gniazdowski
2017-03-18 17:07 ` Bart Schaefer
2017-03-18 17:32   ` Sebastian Gniazdowski
2017-03-18 21:50     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).