mirror of
https://github.com/git/git.git
synced 2026-03-05 06:57:37 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
4a5e529081
commit
657e26658c
@@ -16,7 +16,7 @@
|
||||
#include "fsmonitor--daemon.h"
|
||||
|
||||
#include "simple-ipc.h"
|
||||
#include "khash.h"
|
||||
#include "strmap.h"
|
||||
#include "run-command.h"
|
||||
#include "trace.h"
|
||||
#include "trace2.h"
|
||||
@@ -674,8 +674,6 @@ static int fsmonitor_parse_client_token(const char *buf_token,
|
||||
return 0;
|
||||
}
|
||||
|
||||
KHASH_INIT(str, const char *, int, 0, kh_str_hash_func, kh_str_hash_equal)
|
||||
|
||||
static int do_handle_client(struct fsmonitor_daemon_state *state,
|
||||
const char *command,
|
||||
ipc_server_reply_cb *reply,
|
||||
@@ -692,8 +690,7 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
|
||||
const struct fsmonitor_batch *batch;
|
||||
struct fsmonitor_batch *remainder = NULL;
|
||||
intmax_t count = 0, duplicates = 0;
|
||||
kh_str_t *shown = NULL;
|
||||
int hash_ret;
|
||||
struct strset shown = STRSET_INIT;
|
||||
int do_trivial = 0;
|
||||
int do_flush = 0;
|
||||
int do_cookie = 0;
|
||||
@@ -882,14 +879,14 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
|
||||
* so walk the batch list backwards from the current head back
|
||||
* to the batch (sequence number) they named.
|
||||
*
|
||||
* We use khash to de-dup the list of pathnames.
|
||||
* We use a strset to de-dup the list of pathnames.
|
||||
*
|
||||
* NEEDSWORK: each batch contains a list of interned strings,
|
||||
* so we only need to do pointer comparisons here to build the
|
||||
* hash table. Currently, we're still comparing the string
|
||||
* values.
|
||||
*/
|
||||
shown = kh_init_str();
|
||||
strset_init_with_options(&shown, NULL, 0);
|
||||
for (batch = batch_head;
|
||||
batch && batch->batch_seq_nr > requested_oldest_seq_nr;
|
||||
batch = batch->next) {
|
||||
@@ -899,11 +896,9 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
|
||||
const char *s = batch->interned_paths[k];
|
||||
size_t s_len;
|
||||
|
||||
if (kh_get_str(shown, s) != kh_end(shown))
|
||||
if (!strset_add(&shown, s))
|
||||
duplicates++;
|
||||
else {
|
||||
kh_put_str(shown, s, &hash_ret);
|
||||
|
||||
trace_printf_key(&trace_fsmonitor,
|
||||
"send[%"PRIuMAX"]: %s",
|
||||
count, s);
|
||||
@@ -973,7 +968,7 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
|
||||
trace2_data_intmax("fsmonitor", the_repository, "response/count/duplicates", duplicates);
|
||||
|
||||
cleanup:
|
||||
kh_destroy_str(shown);
|
||||
strset_clear(&shown);
|
||||
strbuf_release(&response_token);
|
||||
strbuf_release(&requested_token_id);
|
||||
strbuf_release(&payload);
|
||||
|
||||
Reference in New Issue
Block a user