From 1ac75d226957cf0ec6b596541f4fd688f49bc300 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 8 Oct 2012 10:41:02 -0700 Subject: [PATCH] allow interner cache to be shared across parsers (#3699) --- src/libsyntax/parse/token.rs | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 19e79a4ae7a..5e928d086b8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -343,28 +343,33 @@ macro_rules! interner_key ( ) fn mk_ident_interner() -> @ident_interner { - /* the indices here must correspond to the numbers in special_idents */ - let init_vec = ~[@~"_", @~"anon", @~"drop", @~"", @~"unary", @~"!", - @~"[]", @~"unary-", @~"__extensions__", @~"self", - @~"item", @~"block", @~"stmt", @~"pat", @~"expr", - @~"ty", @~"ident", @~"path", @~"tt", @~"matchers", - @~"str", @~"TyVisitor", @~"arg", @~"descrim", - @~"__rust_abi", @~"__rust_stack_shim", @~"TyDesc", - @~"dtor", @~"main", @~"", @~"blk", @~"static", - @~"intrinsic", @~"__foreign_mod__"]; - - let rv = @ident_interner { - interner: interner::mk_prefill::<@~str>(init_vec) - }; - - /* having multiple interners will just confuse the serializer */ unsafe { - assert task::local_data::local_data_get(interner_key!()).is_none() - }; - unsafe { - task::local_data::local_data_set(interner_key!(), @rv) - }; - rv + match task::local_data::local_data_get(interner_key!()) { + Some(interner) => *interner, + None => { + // the indices here must correspond to the numbers in + // special_idents. + let init_vec = ~[ + @~"_", @~"anon", @~"drop", @~"", @~"unary", @~"!", + @~"[]", @~"unary-", @~"__extensions__", @~"self", + @~"item", @~"block", @~"stmt", @~"pat", @~"expr", + @~"ty", @~"ident", @~"path", @~"tt", @~"matchers", + @~"str", @~"TyVisitor", @~"arg", @~"descrim", + @~"__rust_abi", @~"__rust_stack_shim", @~"TyDesc", + @~"dtor", @~"main", @~"", @~"blk", @~"static", + @~"intrinsic", @~"__foreign_mod__" + ]; + + let rv = @ident_interner { + interner: interner::mk_prefill(init_vec) + }; + + task::local_data::local_data_set(interner_key!(), @rv); + + rv + } + } + } } /* for when we don't care about the contents; doesn't interact with TLD or