MCPcopy Create free account
hub / github.com/Singular/Singular / Intern

Function Intern

ppcc/src/pplex.cc:51–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49typedef Map<FixStr, Str *> InternMap;
50
51Str *Intern(const char *ptr, Int len) {
52 static InternMap *map = NULL;
53 if (!map) {
54 GCVar(map, new InternMap());
55 }
56 FixStr fs;
57 fs.str = ptr;
58 fs.len = len;
59 Str *result = map->get(fs, NULL);
60 if (!result) {
61 result = new Str(ptr, len);
62 // `ptr` above is an interior pointer whose contents may disappear
63 // due to GC once the `SourceFile` object containing it is no
64 // longer reachable.
65 //
66 // Therefore, we replace it with `result->c_str()`. This is not only
67 // not an interior pointer, but is kept alive by the value that the
68 // key is in use for.
69 fs.str = result->c_str();
70 map->add(fs, result);
71 }
72 return result;
73}
74
75#define PUSH_TOKEN(s) \
76 token.sym = s; \

Callers 1

TokenizeFunction · 0.85

Calls 4

GCVarFunction · 0.85
c_strMethod · 0.80
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected