...
 
Commits (2)
......@@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License along with
// pbvi. If not, see <https://www.gnu.org/licenses/>.
use std::mem::replace;
use std::sync::Arc;
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
......@@ -40,7 +41,7 @@ impl TokenArena {
if id >= self.tokens.len() {
Err(TokenError::invalid_id("set"))
} else {
self.tokens.insert(id, RwLock::new(token));
replace(&mut self.tokens[id], RwLock::new(token));
Ok(())
}
}
......
......@@ -74,7 +74,7 @@ pub fn words(arena: Arc<RwLock<TokenArena>>, values: &str) -> TokenResult<Vec<To
Ok(Token::new_word(
arena.clone(),
id,
&graphemes(arena, value)?,
&graphemes(arena.clone(), value)?,
))
})
}
......@@ -83,7 +83,7 @@ pub fn lines(arena: Arc<RwLock<TokenArena>>, values: &str) -> TokenResult<Vec<To
create_tokens(
arena,
LinesWithEndings::from(values),
&|arena, id, value| Ok(Token::new_line(arena.clone(), id, &words(arena, value)?)),
&|arena, id, value| Ok(Token::new_line(arena.clone(), id, &words(arena.clone(), value)?)),
)
}
......
......@@ -170,9 +170,7 @@ fn parse_words() {
fn line() {
let arena = Arc::new(RwLock::new(TokenArena::new()));
let word_ids = parse::words(arena.clone(), "foo bar baz qux").unwrap();
println!("word ids: {:?}", word_ids);
let line_id = arena.write().reserve_id(arena.clone());
println!("line id: {}", line_id);
let line = Token::new_line(arena.clone(), line_id, &word_ids);
arena.write().set(line_id, line);
......