Skip to content

Commit d1a584f

Browse files
committed
Don't allocate a new string for each new type for the ExceptionZoo
1 parent a77b7e0 commit d1a584f

File tree

1 file changed

+16
-69
lines changed

1 file changed

+16
-69
lines changed

vm/src/exceptions.rs

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -107,90 +107,37 @@ impl ExceptionZoo {
107107
let base_exception_type =
108108
create_type("BaseException", &type_type, &object_type, &dict_type);
109109

110-
let exception_type = create_type(
111-
&String::from("Exception"),
112-
&type_type,
113-
&base_exception_type,
114-
&dict_type,
115-
);
116-
let syntax_error = create_type(
117-
&String::from("SyntaxError"),
118-
&type_type,
119-
&exception_type,
120-
&dict_type,
121-
);
122-
let assertion_error = create_type(
123-
&String::from("AssertionError"),
124-
&type_type,
125-
&exception_type,
126-
&dict_type,
127-
);
110+
let exception_type = create_type("Exception", &type_type, &base_exception_type, &dict_type);
111+
let syntax_error = create_type("SyntaxError", &type_type, &exception_type, &dict_type);
112+
let assertion_error =
113+
create_type("AssertionError", &type_type, &exception_type, &dict_type);
128114
let attribute_error = create_type(
129-
&String::from("AttributeError"),
115+
"AttributeError",
130116
&type_type,
131117
&exception_type.clone(),
132118
&dict_type,
133119
);
134120
let index_error = create_type(
135-
&String::from("IndexError"),
121+
"IndexError",
136122
&type_type,
137123
&exception_type.clone(),
138124
&dict_type,
139125
);
140-
let key_error = create_type(
141-
&String::from("KeyError"),
142-
&type_type,
143-
&exception_type.clone(),
144-
&dict_type,
145-
);
146-
let name_error = create_type(
147-
&String::from("NameError"),
148-
&type_type,
149-
&exception_type.clone(),
150-
&dict_type,
151-
);
152-
let runtime_error = create_type(
153-
&String::from("RuntimeError"),
154-
&type_type,
155-
&exception_type,
156-
&dict_type,
157-
);
126+
let key_error = create_type("KeyError", &type_type, &exception_type.clone(), &dict_type);
127+
let name_error = create_type("NameError", &type_type, &exception_type.clone(), &dict_type);
128+
let runtime_error = create_type("RuntimeError", &type_type, &exception_type, &dict_type);
158129
let not_implemented_error = create_type(
159-
&String::from("NotImplementedError"),
130+
"NotImplementedError",
160131
&type_type,
161132
&runtime_error,
162133
&dict_type,
163134
);
164-
let stop_iteration = create_type(
165-
&String::from("StopIteration"),
166-
&type_type,
167-
&exception_type,
168-
&dict_type,
169-
);
170-
let type_error = create_type(
171-
&String::from("TypeError"),
172-
&type_type,
173-
&exception_type,
174-
&dict_type,
175-
);
176-
let value_error = create_type(
177-
&String::from("ValueError"),
178-
&type_type,
179-
&exception_type,
180-
&dict_type,
181-
);
182-
let import_error = create_type(
183-
&String::from("ImportError"),
184-
&type_type,
185-
&exception_type,
186-
&dict_type,
187-
);
188-
let module_not_found_error = create_type(
189-
&String::from("ModuleNotFoundError"),
190-
&type_type,
191-
&import_error,
192-
&dict_type,
193-
);
135+
let stop_iteration = create_type("StopIteration", &type_type, &exception_type, &dict_type);
136+
let type_error = create_type("TypeError", &type_type, &exception_type, &dict_type);
137+
let value_error = create_type("ValueError", &type_type, &exception_type, &dict_type);
138+
let import_error = create_type("ImportError", &type_type, &exception_type, &dict_type);
139+
let module_not_found_error =
140+
create_type("ModuleNotFoundError", &type_type, &import_error, &dict_type);
194141

195142
ExceptionZoo {
196143
base_exception_type: base_exception_type,

0 commit comments

Comments
 (0)