… | |
… | |
49 | static HT ht; |
49 | static HT ht; |
50 | |
50 | |
51 | const char * |
51 | const char * |
52 | shstr::find (const char *s) |
52 | shstr::find (const char *s) |
53 | { |
53 | { |
|
|
54 | if (!s) |
|
|
55 | return s; |
|
|
56 | |
54 | HT::iterator i = ht.find (s); |
57 | HT::iterator i = ht.find (s); |
55 | |
58 | |
56 | return i != ht.end () |
59 | return i != ht.end () |
57 | ? (char *)*i |
60 | ? (char *)*i |
58 | : 0; |
61 | : 0; |
59 | } |
62 | } |
60 | |
63 | |
61 | const char * |
64 | const char * |
62 | shstr::intern (const char *s) |
65 | shstr::intern (const char *s) |
63 | { |
66 | { |
64 | HT::iterator i = ht.find (s); |
67 | if (!s) |
|
|
68 | return s; |
65 | |
69 | |
66 | if (i != ht.end ()) |
70 | if (const char *found = find (s)) |
67 | return (char *)*i; |
71 | return found; |
68 | |
72 | |
69 | int len = strlen (s); |
73 | int len = strlen (s); |
70 | |
74 | |
71 | int *v = (int *)malloc (sizeof (int) * 2 + len + 1); |
75 | int *v = (int *)malloc (sizeof (int) * 2 + len + 1); |
72 | |
76 | |