File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 1
1
//! Implementation of the full Intcode computer specification.
2
2
use std:: collections:: VecDeque ;
3
3
4
+ const EXTRA : usize = 2_000 ;
5
+
4
6
pub enum State {
5
7
Input ,
6
8
Output ( i64 ) ,
@@ -15,8 +17,12 @@ pub struct Computer {
15
17
}
16
18
17
19
impl Computer {
18
- pub fn new ( code : & [ i64 ] ) -> Computer {
19
- Computer { pc : 0 , base : 0 , code : code. to_vec ( ) , input : VecDeque :: new ( ) }
20
+ pub fn new ( input : & [ i64 ] ) -> Computer {
21
+ let mut code = Vec :: with_capacity ( input. len ( ) + EXTRA ) ;
22
+ code. extend_from_slice ( input) ;
23
+ code. resize ( input. len ( ) + EXTRA , 0 ) ;
24
+
25
+ Computer { pc : 0 , base : 0 , code, input : VecDeque :: new ( ) }
20
26
}
21
27
22
28
pub fn input ( & mut self , value : i64 ) {
@@ -120,10 +126,6 @@ impl Computer {
120
126
_ => unreachable ! ( ) ,
121
127
} ;
122
128
123
- if index >= self . code . len ( ) {
124
- self . code . resize ( index + 1 , 0 ) ;
125
- }
126
-
127
129
index
128
130
}
129
131
}
You can’t perform that action at this time.
0 commit comments