Skip to content

Commit e93431a

Browse files
ptarjangitster
authored andcommitted
fsmonitor: convert shown khash to strset in do_handle_client
Replace the khash-based string set used for deduplicating pathnames in do_handle_client() with a strset, which provides a cleaner interface for the same purpose. Since the paths are interned strings from the batch data, use strdup_strings=0 to avoid unnecessary copies. Suggested-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Paul Tarjan <github@paulisageek.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7241bc1 commit e93431a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

builtin/fsmonitor--daemon.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "fsmonitor--daemon.h"
1717

1818
#include "simple-ipc.h"
19-
#include "khash.h"
19+
#include "strmap.h"
2020
#include "run-command.h"
2121
#include "trace.h"
2222
#include "trace2.h"
@@ -674,8 +674,6 @@ static int fsmonitor_parse_client_token(const char *buf_token,
674674
return 0;
675675
}
676676

677-
KHASH_INIT(str, const char *, int, 0, kh_str_hash_func, kh_str_hash_equal)
678-
679677
static int do_handle_client(struct fsmonitor_daemon_state *state,
680678
const char *command,
681679
ipc_server_reply_cb *reply,
@@ -692,8 +690,7 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
692690
const struct fsmonitor_batch *batch;
693691
struct fsmonitor_batch *remainder = NULL;
694692
intmax_t count = 0, duplicates = 0;
695-
kh_str_t *shown = NULL;
696-
int hash_ret;
693+
struct strset shown = STRSET_INIT;
697694
int do_trivial = 0;
698695
int do_flush = 0;
699696
int do_cookie = 0;
@@ -882,14 +879,14 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
882879
* so walk the batch list backwards from the current head back
883880
* to the batch (sequence number) they named.
884881
*
885-
* We use khash to de-dup the list of pathnames.
882+
* We use a strset to de-dup the list of pathnames.
886883
*
887884
* NEEDSWORK: each batch contains a list of interned strings,
888885
* so we only need to do pointer comparisons here to build the
889886
* hash table. Currently, we're still comparing the string
890887
* values.
891888
*/
892-
shown = kh_init_str();
889+
strset_init_with_options(&shown, NULL, 0);
893890
for (batch = batch_head;
894891
batch && batch->batch_seq_nr > requested_oldest_seq_nr;
895892
batch = batch->next) {
@@ -899,11 +896,9 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
899896
const char *s = batch->interned_paths[k];
900897
size_t s_len;
901898

902-
if (kh_get_str(shown, s) != kh_end(shown))
899+
if (!strset_add(&shown, s))
903900
duplicates++;
904901
else {
905-
kh_put_str(shown, s, &hash_ret);
906-
907902
trace_printf_key(&trace_fsmonitor,
908903
"send[%"PRIuMAX"]: %s",
909904
count, s);
@@ -973,7 +968,7 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
973968
trace2_data_intmax("fsmonitor", the_repository, "response/count/duplicates", duplicates);
974969

975970
cleanup:
976-
kh_destroy_str(shown);
971+
strset_clear(&shown);
977972
strbuf_release(&response_token);
978973
strbuf_release(&requested_token_id);
979974
strbuf_release(&payload);

0 commit comments

Comments
 (0)