Skip to content

Commit 741afa3

Browse files
committed
Remove a last println and use a static default parser
Heap profilers are fun
1 parent 4d7c5dd commit 741afa3

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

build_pycompat.py

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/python3
12
from dateutil.parser import parse
23
from dateutil.tz import tzutc
34
from datetime import datetime
@@ -232,7 +233,7 @@ def test_fuzzy_simple(i, s):
232233
tzinfos: &HashMap<String, i32>,
233234
) {
234235
235-
let mut parser = Parser::new(info);
236+
let parser = Parser::new(info);
236237
let rs_parsed = parser.parse(
237238
s,
238239
dayfirst,
@@ -282,7 +283,7 @@ def test_fuzzy_simple(i, s):
282283
tzinfos: &HashMap<String, i32>,
283284
) {
284285
285-
let mut parser = Parser::new(info);
286+
let parser = Parser::new(info);
286287
let rs_parsed = parser.parse(
287288
s,
288289
dayfirst,

build_pycompat_tokenizer.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/python3
12
from dateutil.parser import _timelex
23

34
from build_pycompat import tests

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ lazy_static! {
108108
static ref ONE: Decimal = Decimal::new(1, 0);
109109
static ref TWENTY_FOUR: Decimal = Decimal::new(24, 0);
110110
static ref SIXTY: Decimal = Decimal::new(60, 0);
111+
static ref DEFAULT_PARSER: Parser = Parser::default();
111112
}
112113

113114
impl From<DecimalError> for ParseError {
@@ -670,7 +671,7 @@ impl Parser {
670671
/// order to be resolved.
671672
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // Need to release a 2.0 for changing public API
672673
pub fn parse(
673-
&mut self,
674+
&self,
674675
timestr: &str,
675676
dayfirst: Option<bool>,
676677
yearfirst: Option<bool>,
@@ -699,7 +700,7 @@ impl Parser {
699700

700701
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // Imitating Python API is priority
701702
fn parse_with_tokens(
702-
&mut self,
703+
&self,
703704
timestr: &str,
704705
dayfirst: Option<bool>,
705706
yearfirst: Option<bool>,
@@ -953,7 +954,6 @@ impl Parser {
953954
) -> ParseResult<Option<FixedOffset>> {
954955
// TODO: Actual timezone support
955956
if let Some(offset) = res.tzoffset {
956-
println!("offset={}", offset);
957957
Ok(Some(FixedOffset::east(offset)))
958958
} else if res.tzoffset == None
959959
&& (res.tzname == Some(" ".to_owned()) || res.tzname == Some(".".to_owned())
@@ -1283,7 +1283,7 @@ fn ljust(s: &str, chars: usize, replace: char) -> String {
12831283
/// The default implementation assumes English values for names of months,
12841284
/// days of the week, etc. It is equivalent to Python's `dateutil.parser.parse()`
12851285
pub fn parse(timestr: &str) -> ParseResult<(NaiveDateTime, Option<FixedOffset>)> {
1286-
let res = Parser::default().parse(
1286+
let res = DEFAULT_PARSER.parse(
12871287
timestr,
12881288
None,
12891289
None,

src/tests/fuzzing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn test_fuzz() {
1616
// OverflowError: Python int too large to convert to C long
1717
// assert_eq!(parse("8888884444444888444444444881"), Err(ParseError::AmPmWithoutHour));
1818
let default = NaiveDate::from_ymd(2016, 6, 29).and_hms(0, 0, 0);
19-
let mut p = Parser::default();
19+
let p = Parser::default();
2020
let res = p.parse("\x0D\x31", None, None, false, false, Some(&default), false, &HashMap::new()).unwrap();
2121
assert_eq!(res.0, default);
2222

src/tests/pycompat_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn parse_and_assert(
3939
tzinfos: &HashMap<String, i32>,
4040
) {
4141

42-
let mut parser = Parser::new(info);
42+
let parser = Parser::new(info);
4343
let rs_parsed = parser.parse(
4444
s,
4545
dayfirst,
@@ -89,7 +89,7 @@ fn parse_fuzzy_and_assert(
8989
tzinfos: &HashMap<String, i32>,
9090
) {
9191

92-
let mut parser = Parser::new(info);
92+
let parser = Parser::new(info);
9393
let rs_parsed = parser.parse(
9494
s,
9595
dayfirst,

0 commit comments

Comments
 (0)