File tree Expand file tree Collapse file tree 5 files changed +58
-7
lines changed
Expand file tree Collapse file tree 5 files changed +58
-7
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,7 @@ else()
242242 option (ENABLE_TESTS "Build tests" OFF )
243243 option (ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF )
244244endif ()
245+ option (USE_XXHASH "Use xxhash if available" ON )
245246option (ENABLE_PERF_TESTS "Build performance tests" OFF )
246247option (ENABLE_COVERAGE "Build code coverage report from tests" OFF )
247248option (ENABLE_FUZZ_TARGETS "Build target programs suitable for fuzzing with AFL" OFF )
@@ -412,9 +413,15 @@ include_directories(${PCRE2_INCLUDE_DIRS})
412413target_link_libraries (yang ${PCRE2_LIBRARIES} )
413414
414415# XXHash include and library
415- find_package (XXHash REQUIRED)
416- include_directories (${XXHASH_INCLUDE_DIR} )
417- target_link_libraries (yang ${XXHASH_LIBRARY} )
416+ find_package (XXHash)
417+ if (XXHASH_FOUND AND USE_XXHASH)
418+ add_definitions (-DUSE_XXHASH)
419+ include_directories (${XXHASH_INCLUDE_DIR} )
420+ target_link_libraries (yang ${XXHASH_LIBRARY} )
421+ else ()
422+ set (USE_XXHASH OFF )
423+ message (STATUS "xxhash not found, USE_XXHASH turned OFF" )
424+ endif ()
418425
419426# generated header list
420427foreach (h IN LISTS gen_headers)
Original file line number Diff line number Diff line change 2020#include <stdint.h>
2121#include <stdlib.h>
2222#include <string.h>
23- #include <xxhash.h>
2423
2524#include "compat.h"
2625#include "dict.h"
2726#include "log.h"
2827#include "ly_common.h"
2928
29+ #ifdef USE_XXHASH
30+ #include <xxhash.h>
31+
3032LIBYANG_API_DEF uint32_t
3133lyht_hash_multi (uint32_t hash , const char * key_part , size_t len )
3234{
@@ -43,6 +45,39 @@ lyht_hash(const char *key, size_t len)
4345 return XXH3_64bits (key , len );
4446}
4547
48+ #else
49+
50+ LIBYANG_API_DEF uint32_t
51+ lyht_hash_multi (uint32_t hash , const char * key_part , size_t len )
52+ {
53+ uint32_t i ;
54+
55+ if (key_part && len ) {
56+ for (i = 0 ; i < len ; ++ i ) {
57+ hash += key_part [i ];
58+ hash += (hash << 10 );
59+ hash ^= (hash >> 6 );
60+ }
61+ } else {
62+ hash += (hash << 3 );
63+ hash ^= (hash >> 11 );
64+ hash += (hash << 15 );
65+ }
66+
67+ return hash ;
68+ }
69+
70+ LIBYANG_API_DEF uint32_t
71+ lyht_hash (const char * key , size_t len )
72+ {
73+ uint32_t hash ;
74+
75+ hash = lyht_hash_multi (0 , key , len );
76+ return lyht_hash_multi (hash , NULL , len );
77+ }
78+
79+ #endif
80+
4681static LY_ERR
4782lyht_init_hlists_and_records (struct ly_ht * ht )
4883{
Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ function(ly_add_utest)
3030 endif ()
3131 endif ()
3232
33- target_link_libraries (${TEST_NAME} ${XXHASH_LIBRARY} )
33+ if (USE_XXHASH)
34+ target_link_libraries (${TEST_NAME} ${XXHASH_LIBRARY} )
35+ endif ()
3436 add_test (NAME ${TEST_NAME} COMMAND ${TEST_NAME} )
3537 set_property (TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3" )
3638
Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ set(format_sources
66add_executable (ly_perf ${CMAKE_CURRENT_SOURCE_DIR} /perf.c $<TARGET_OBJECTS:yangobj>)
77set_target_properties (ly_perf PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /tests" )
88target_link_libraries (ly_perf ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS} )
9- target_link_libraries (ly_perf ${XXHASH_LIBRARY} )
9+ if (USE_XXHASH)
10+ target_link_libraries (ly_perf ${XXHASH_LIBRARY} )
11+ endif ()
12+
1013if (NOT WIN32 )
1114 target_link_libraries (ly_perf m)
1215endif ()
Original file line number Diff line number Diff line change 88# just compile
99add_executable (cpp_compat cpp_compat.c $<TARGET_OBJECTS:yangobj>)
1010target_include_directories (cpp_compat BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
11- target_link_libraries (cpp_compat ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS} m ${XXHASH_LIBRARY} )
11+ target_link_libraries (cpp_compat ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS} m)
12+ if (USE_XXHASH)
13+ target_link_libraries (cpp_compat ${XXHASH_LIBRARY} )
14+ endif ()
15+
1216target_compile_options (cpp_compat PUBLIC "-Werror=c++-compat" )
You can’t perform that action at this time.
0 commit comments