From: "Václav Zeman" <vhaisman@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: Large LS_COLORS makes auto_cd very slow
Date: Fri, 6 Apr 2012 11:49:47 +0200 [thread overview]
Message-ID: <CAKw7uVgBwObws9V1nFCaBGAYof_r2DjwcP2ajxKNoMNUuCOVwA@mail.gmail.com> (raw)
In-Reply-To: <120405085125.ZM13673@torch.brasslantern.com>
[-- Attachment #1: Type: text/plain, Size: 797 bytes --]
On 5 April 2012 17:51, Bart Schaefer wrote:
> On Apr 5, 11:30am, Vaclav Zeman wrote:
> }
> } > Anybody want to have a stab at creating a vastly more efficient version
> } > of Src/params.c:arrayuniq() ?
> } I wonder if the attached patch does what you want here. It is fairly
> } untested and incomplete as I have not been able to find out how to
> } make sure that search.h gets included.
>
> Zsh has its own hash table implementation which ought to be used rather
> than introducing any new external dependencies, but otherwise this is
> the kind of thing I was suggesting.
>
> Or perhaps someone else has an even more clever idea. Anything better
> than O(N^2) would help.
I have reimplemented the change using ZSH's own hash table. Please see
the attached patch.
--
VZ
[-- Attachment #2: hash_arrayuniq-2.diff.txt --]
[-- Type: text/plain, Size: 1877 bytes --]
=== modified file 'Src/params.c'
--- Src/params.c 2012-03-13 09:47:01 +0000
+++ Src/params.c 2012-04-06 09:42:20 +0000
@@ -29,6 +29,7 @@
#include "zsh.mdh"
#include "params.pro"
+#include "hashtable.pro"
#include "version.h"
#ifdef CUSTOM_PATCHLEVEL
@@ -3456,7 +3457,7 @@
/**/
static void
-arrayuniq(char **x, int freeok)
+simple_arrayuniq(char **x, int freeok)
{
char **t, **p = x;
@@ -3471,6 +3472,73 @@
}
/**/
+static void
+arrayuniq_freenode(HashNode hn)
+{
+ (void)hn;
+}
+
+/**/
+static void
+arrayuniq(char **x, int freeok)
+{
+ char **it, **write_it;
+ size_t array_size;
+ int ret;
+ HashNode found_item;
+ struct hashnode new_node;
+ HashTable ht;
+
+ if (*x == NULL)
+ return;
+
+ for (it = x; *it != NULL; ++it)
+ ;
+
+ array_size = it - x;
+ if (array_size <= 10u) {
+ /* fallback to simpler routine */
+ simple_arrayuniq(x, freeok);
+ return;
+ }
+
+ ht = newhashtable((int)array_size * 2, "arrayuniq", NULL);
+ /* ??? error checking */
+ ht->hash = hasher;
+ ht->emptytable = emptyhashtable;
+ ht->filltable = NULL;
+ ht->cmpnodes = strcmp;
+ ht->addnode = addhashnode;
+ ht->getnode = gethashnode2;
+ ht->getnode2 = gethashnode2;
+ ht->removenode = removehashnode;
+ ht->disablenode = disablehashnode;
+ ht->enablenode = enablehashnode;
+ ht->freenode = arrayuniq_freenode;
+ ht->printnode = NULL;
+
+ for (it = x, write_it = x; *it;) {
+ found_item = gethashnode(ht, *it);
+ if (! found_item) {
+ found_item = addhashnode2(ht, *it, &new_node);
+ /*assert(! found_item);*/
+ *write_it = *it;
+ if (it != write_it)
+ *it = NULL;
+ ++write_it;
+ }
+ else {
+ if (freeok)
+ zsfree(*it);
+ *it = NULL;
+ }
+ ++it;
+ }
+
+ deletehashtable(ht);
+}
+
+/**/
void
uniqarray(char **x)
{
next prev parent reply other threads:[~2012-04-06 9:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 19:08 Jesper Nygårds
2012-04-04 7:52 ` Bart Schaefer
2012-04-04 16:57 ` Jesper Nygårds
2012-04-05 9:30 ` Václav Zeman
2012-04-05 15:51 ` Bart Schaefer
2012-04-05 16:33 ` Bart Schaefer
2012-04-05 17:00 ` Philippe Troin
2012-04-06 9:49 ` Václav Zeman [this message]
2012-04-06 11:07 ` Mark van Dijk
2012-04-06 15:51 ` Bart Schaefer
2012-04-09 8:23 ` Václav Zeman
2012-04-09 19:28 ` Bart Schaefer
2012-04-06 18:30 ` Valodim Skywalker
2012-04-07 16:43 ` Bart Schaefer
2013-01-11 11:30 Completing all possible candidates Jesper Nygårds
2013-01-11 14:32 ` Bart Schaefer
2013-01-15 7:28 ` Jesper Nygårds
2013-01-17 3:14 ` Bart Schaefer
2013-01-17 6:28 ` Jesper Nygårds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKw7uVgBwObws9V1nFCaBGAYof_r2DjwcP2ajxKNoMNUuCOVwA@mail.gmail.com \
--to=vhaisman@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).