Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf956ecd

Browse files
committed
Convert uses of hash_string_pointer to fasthash equivalent
Remove duplicate hash_string_pointer() function definitions by creatinga new inline function hash_string() for this purpose.This has the added advantage of avoiding strlen() calls when doing hashlookup. It's not clear how many of these are perfomance-sensitiveenough to benefit from that, but the simplification is worth it onits own.Reviewed by Jeff DavisDiscussion:https://postgr.es/m/CANWCAZbg_XeSeY0a_PqWmWqeRATvzTzUNYRLeT%2Bbzs%2BYQdC92g%40mail.gmail.com
1 parentdb17594 commitf956ecd

File tree

5 files changed

+28
-58
lines changed

5 files changed

+28
-58
lines changed

‎src/bin/pg_combinebackup/load_manifest.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include<sys/stat.h>
1616
#include<unistd.h>
1717

18-
#include"common/hashfn.h"
18+
#include"common/hashfn_unstable.h"
1919
#include"common/logging.h"
2020
#include"common/parse_manifest.h"
2121
#include"load_manifest.h"
@@ -44,12 +44,11 @@
4444
* Define a hash table which we can use to store information about the files
4545
* mentioned in the backup manifest.
4646
*/
47-
staticuint32hash_string_pointer(char*s);
4847
#defineSH_PREFIXmanifest_files
4948
#defineSH_ELEMENT_TYPEmanifest_file
5049
#defineSH_KEY_TYPEchar *
5150
#defineSH_KEYpathname
52-
#defineSH_HASH_KEY(tb,key)hash_string_pointer(key)
51+
#defineSH_HASH_KEY(tb,key)hash_string(key)
5352
#defineSH_EQUAL(tb,a,b)(strcmp(a, b) == 0)
5453
#defineSH_SCOPEextern
5554
#defineSH_RAW_ALLOCATORpg_malloc0
@@ -311,14 +310,3 @@ combinebackup_per_wal_range_cb(JsonManifestParseContext *context,
311310
manifest->last_wal_range->next=range;
312311
manifest->last_wal_range=range;
313312
}
314-
315-
/*
316-
* Helper function for manifest_files hash table.
317-
*/
318-
staticuint32
319-
hash_string_pointer(char*s)
320-
{
321-
unsignedchar*ss= (unsignedchar*)s;
322-
323-
returnhash_bytes(ss,strlen(s));
324-
}

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include"catalog/pg_authid_d.h"
2222
#include"common/connect.h"
2323
#include"common/file_utils.h"
24-
#include"common/hashfn.h"
24+
#include"common/hashfn_unstable.h"
2525
#include"common/logging.h"
2626
#include"common/string.h"
2727
#include"dumputils.h"
@@ -33,8 +33,6 @@
3333
/* version string we expect back from pg_dump */
3434
#definePGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
3535

36-
staticuint32hash_string_pointer(char*s);
37-
3836
typedefstruct
3937
{
4038
uint32status;
@@ -46,7 +44,7 @@ typedef struct
4644
#defineSH_ELEMENT_TYPERoleNameEntry
4745
#defineSH_KEY_TYPEchar *
4846
#defineSH_KEYrolename
49-
#defineSH_HASH_KEY(tb,key)hash_string_pointer(key)
47+
#defineSH_HASH_KEY(tb,key)hash_string(key)
5048
#defineSH_EQUAL(tb,a,b)(strcmp(a, b) == 0)
5149
#defineSH_STORE_HASH
5250
#defineSH_GET_HASH(tb,a)(a)->hashval
@@ -1938,17 +1936,6 @@ dumpTimestamp(const char *msg)
19381936
fprintf(OPF,"-- %s %s\n\n",msg,buf);
19391937
}
19401938

1941-
/*
1942-
* Helper function for rolename_hash hash table.
1943-
*/
1944-
staticuint32
1945-
hash_string_pointer(char*s)
1946-
{
1947-
unsignedchar*ss= (unsignedchar*)s;
1948-
1949-
returnhash_bytes(ss,strlen(s));
1950-
}
1951-
19521939
/*
19531940
* read_dumpall_filters - retrieve database identifier patterns from file
19541941
*

‎src/bin/pg_rewind/filemap.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include"catalog/pg_tablespace_d.h"
3030
#include"common/file_utils.h"
31-
#include"common/hashfn.h"
31+
#include"common/hashfn_unstable.h"
3232
#include"common/string.h"
3333
#include"datapagemap.h"
3434
#include"filemap.h"
@@ -38,12 +38,11 @@
3838
* Define a hash table which we can use to store information about the files
3939
* appearing in source and target systems.
4040
*/
41-
staticuint32hash_string_pointer(constchar*s);
4241
#defineSH_PREFIXfilehash
4342
#defineSH_ELEMENT_TYPEfile_entry_t
4443
#defineSH_KEY_TYPEconst char *
4544
#defineSH_KEYpath
46-
#defineSH_HASH_KEY(tb,key)hash_string_pointer(key)
45+
#defineSH_HASH_KEY(tb,key)hash_string(key)
4746
#defineSH_EQUAL(tb,a,b)(strcmp(a, b) == 0)
4847
#defineSH_SCOPEstatic inline
4948
#defineSH_RAW_ALLOCATORpg_malloc0
@@ -821,15 +820,3 @@ decide_file_actions(void)
821820

822821
returnfilemap;
823822
}
824-
825-
826-
/*
827-
* Helper function for filemap hash table.
828-
*/
829-
staticuint32
830-
hash_string_pointer(constchar*s)
831-
{
832-
unsignedchar*ss= (unsignedchar*)s;
833-
834-
returnhash_bytes(ss,strlen(s));
835-
}

‎src/bin/pg_verifybackup/pg_verifybackup.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include<time.h>
2020

2121
#include"common/controldata_utils.h"
22-
#include"common/hashfn.h"
22+
#include"common/hashfn_unstable.h"
2323
#include"common/logging.h"
2424
#include"common/parse_manifest.h"
2525
#include"fe_utils/simple_list.h"
@@ -68,12 +68,11 @@ typedef struct manifest_file
6868
* Define a hash table which we can use to store information about the files
6969
* mentioned in the backup manifest.
7070
*/
71-
staticuint32hash_string_pointer(char*s);
7271
#defineSH_PREFIXmanifest_files
7372
#defineSH_ELEMENT_TYPEmanifest_file
7473
#defineSH_KEY_TYPEchar *
7574
#defineSH_KEYpathname
76-
#defineSH_HASH_KEY(tb,key)hash_string_pointer(key)
75+
#defineSH_HASH_KEY(tb,key)hash_string(key)
7776
#defineSH_EQUAL(tb,a,b)(strcmp(a, b) == 0)
7877
#defineSH_SCOPEstatic inline
7978
#defineSH_RAW_ALLOCATORpg_malloc0
@@ -1028,17 +1027,6 @@ should_ignore_relpath(verifier_context *context, char *relpath)
10281027
return false;
10291028
}
10301029

1031-
/*
1032-
* Helper function for manifest_files hash table.
1033-
*/
1034-
staticuint32
1035-
hash_string_pointer(char*s)
1036-
{
1037-
unsignedchar*ss= (unsignedchar*)s;
1038-
1039-
returnhash_bytes(ss,strlen(s));
1040-
}
1041-
10421030
/*
10431031
* Print a progress report based on the global variables.
10441032
*

‎src/include/common/hashfn_unstable.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,24 @@ fasthash32(const char *k, size_t len, uint64 seed)
370370
returnfasthash_reduce32(fasthash64(k,len,seed));
371371
}
372372

373+
/*
374+
* Convenience function for hashing NUL-terminated strings
375+
*/
376+
staticinlineuint32
377+
hash_string(constchar*s)
378+
{
379+
fasthash_statehs;
380+
size_ts_len;
381+
382+
fasthash_init(&hs,0);
383+
384+
/*
385+
* Combine string into the hash and save the length for tweaking the final
386+
* mix.
387+
*/
388+
s_len=fasthash_accum_cstring(&hs,s);
389+
390+
returnfasthash_final32(&hs,s_len);
391+
}
392+
373393
#endif/* HASHFN_UNSTABLE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp