@@ -99,6 +99,8 @@ type crate_ctxt = {
99
99
type_use_cache : hashmap < ast:: def_id , [ type_use:: type_uses ] > ,
100
100
// Cache generated vtables
101
101
vtables : hashmap < mono_id , ValueRef > ,
102
+ // Cache of constant strings,
103
+ const_cstr_cache : hashmap < str , ValueRef > ,
102
104
module_data : hashmap < str , ValueRef > ,
103
105
lltypes : hashmap < ty:: t , TypeRef > ,
104
106
names : namegen ,
@@ -762,6 +764,11 @@ fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i as u64, False); }
762
764
// This is a 'c-like' raw string, which differs from
763
765
// our boxed-and-length-annotated strings.
764
766
fn C_cstr ( cx : @crate_ctxt , s : str ) -> ValueRef {
767
+ alt cx. const_cstr_cache . find ( s) {
768
+ some ( llval) { ret llval; }
769
+ none { }
770
+ }
771
+
765
772
let sc = str:: as_c_str ( s) { |buf|
766
773
llvm:: LLVMConstString ( buf, str:: len ( s) as c_uint , False )
767
774
} ;
@@ -771,6 +778,9 @@ fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef {
771
778
llvm:: LLVMSetInitializer ( g, sc) ;
772
779
llvm:: LLVMSetGlobalConstant ( g, True ) ;
773
780
lib:: llvm:: SetLinkage ( g, lib:: llvm:: InternalLinkage ) ;
781
+
782
+ cx. const_cstr_cache . insert ( s, g) ;
783
+
774
784
ret g;
775
785
}
776
786
0 commit comments