MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve interning fingerprint

+7 -45
+1 -1
meson.build
··· 79 79 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 80 80 81 81 version_conf = configuration_data() 82 - version_conf.set('ANT_VERSION', '0.2.2.12') 82 + version_conf.set('ANT_VERSION', '0.2.2.13') 83 83 version_conf.set('ANT_GIT_HASH', git_hash) 84 84 version_conf.set('ANT_BUILD_DATE', build_date) 85 85
+6 -44
src/ant.c
··· 2769 2769 return js_mkundef(); 2770 2770 } 2771 2771 2772 - static bool is_const_prop(struct js *js, jsoff_t propoff) { 2772 + static inline bool is_const_prop(struct js *js, jsoff_t propoff) { 2773 2773 jsoff_t v = loadoff(js, propoff); 2774 2774 return (v & CONSTMASK) != 0; 2775 2775 } ··· 2790 2790 return hash; 2791 2791 } 2792 2792 2793 - static const char *intern_string_h(const char *str, size_t len, uint64_t h) { 2793 + static const char *intern_string(const char *str, size_t len) { 2794 + uint64_t h = hash_key(str, len); 2794 2795 uint32_t bucket = (uint32_t)(h & (INTERN_BUCKETS - 1)); 2795 2796 2796 2797 for (interned_string_t *e = intern_buckets[bucket]; e; e = e->next) { 2797 - if (e->hash == h && e->len == len) { 2798 - return e->str; 2799 - } 2798 + if (e->hash == h && e->len == len && memcmp(e->str, str, len) == 0) return e->str; 2800 2799 } 2801 2800 2802 2801 interned_string_t *entry = (interned_string_t *)malloc(sizeof(interned_string_t)); 2803 2802 if (!entry) return NULL; 2804 2803 entry->str = (char *)malloc(len + 1); 2805 2804 if (!entry->str) { free(entry); return NULL; } 2805 + 2806 2806 memcpy(entry->str, str, len); 2807 2807 entry->str[len] = '\0'; 2808 2808 entry->len = len; 2809 2809 entry->hash = h; 2810 2810 entry->next = intern_buckets[bucket]; 2811 2811 intern_buckets[bucket] = entry; 2812 - return entry->str; 2813 - } 2814 - 2815 - typedef struct { 2816 - const char *str; 2817 - size_t len; 2818 - const char *result; 2819 - uint64_t fingerprint; 2820 - } intern_cache_entry_t; 2821 - 2822 - #define INTERN_CACHE_SIZE 1024 2823 - static intern_cache_entry_t intern_cache[INTERN_CACHE_SIZE]; 2824 - 2825 - static inline uint64_t make_fingerprint(const char *str, size_t len) { 2826 - if (len == 0) return 0; 2827 - uint64_t fp = len; 2828 - fp |= ((uint64_t)(unsigned char)str[0]) << 8; 2829 - if (len > 1) fp |= ((uint64_t)(unsigned char)str[1]) << 16; 2830 - if (len > 2) fp |= ((uint64_t)(unsigned char)str[len - 1]) << 24; 2831 - if (len > 4) fp |= ((uint64_t)(unsigned char)str[len >> 1]) << 32; 2832 - if (len > 8) fp |= ((uint64_t)(unsigned char)str[len >> 2]) << 40; 2833 - if (len > 16) fp |= ((uint64_t)(unsigned char)str[(len >> 1) + (len >> 2)]) << 48; 2834 - return fp; 2835 - } 2836 - 2837 - static const char *intern_string(const char *str, size_t len) { 2838 - uint32_t slot = (((uintptr_t)str >> 3) ^ ((uintptr_t)str >> 11)) & (INTERN_CACHE_SIZE - 1); 2839 - intern_cache_entry_t *e = &intern_cache[slot]; 2840 2812 2841 - if (e->str == str && e->len == len) { 2842 - uint64_t fp = make_fingerprint(str, len); 2843 - if (e->fingerprint == fp) return e->result; 2844 - } 2845 - 2846 - const char *result = intern_string_h(str, len, hash_key(str, len)); 2847 - e->str = str; 2848 - e->len = len; 2849 - e->result = result; 2850 - e->fingerprint = make_fingerprint(str, len); 2851 - return result; 2813 + return entry->str; 2852 2814 } 2853 2815 2854 2816 static void intern_init(void) {