Skip to content

Commit 362848a

Browse files
committed
No need to transform into string to collect token for Halstead metric
1 parent 2cf8368 commit 362848a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/halstead.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::*;
1111
#[derive(Default, Debug)]
1212
pub struct Stats<'a> {
1313
pub operators: FxHashMap<u16, u64>,
14-
pub operands: FxHashMap<&'a str, u64>,
14+
pub operands: FxHashMap<&'a [u8], u64>,
1515
}
1616

1717
impl Serialize for Stats<'_> {
@@ -120,9 +120,9 @@ where
120120
fn compute<'a>(_node: &Node<'a>, _code: &'a [u8], _stats: &mut Stats<'a>) {}
121121
}
122122

123-
fn get_id<'a>(node: &Node<'a>, code: &'a [u8]) -> &'a str {
124-
let code = &code[node.start_byte()..node.end_byte()];
125-
std::str::from_utf8(code).unwrap()
123+
#[inline(always)]
124+
fn get_id<'a>(node: &Node<'a>, code: &'a [u8]) -> &'a [u8] {
125+
&code[node.start_byte()..node.end_byte()]
126126
}
127127

128128
impl Halstead for PythonCode {

0 commit comments

Comments
 (0)