Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions std/datetime/date.d
Original file line number Diff line number Diff line change
Expand Up @@ -3055,20 +3055,19 @@ public:
if (isSomeString!S)
{
import std.algorithm.searching : countUntil;
import std.conv : to;
import std.exception : enforce;
import std.format : format;
import std.string : strip;

immutable dstr = to!dstring(strip(isoString));
immutable str = strip(isoString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work to use byCodeUnit here? Presumably, the speed-up is from getting rid of allocating the dstring, but you're introducing more auto-decoding in the process. If byCodeUnit doesn't work here at the moment (e.g. due to a function still requiring actual strings), then this is still clearly better, but I'd prefer to have byCodeUnit used if we can.

Copy link
Contributor Author

@JackStouffer JackStouffer Jul 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmdavis None of the functions here use auto decoding. I've already removed it from Date.fromISOString and TimeOfDay.fromISOString, and countUntil with a single needle forwards to find, which already deals with auto-decoding.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that strip and countUntil both did, but if they don't, then that's not an issue (though actually, I should probably know for strip, since I did a rewrite of that at one point - but I guess that it was long enough ago that I forgot).


enforce(dstr.length >= 15, new DateTimeException(format("Invalid ISO String: %s", isoString)));
auto t = dstr.countUntil('T');
enforce(str.length >= 15, new DateTimeException(format("Invalid ISO String: %s", isoString)));
auto t = str.countUntil('T');

enforce(t != -1, new DateTimeException(format("Invalid ISO String: %s", isoString)));

immutable date = Date.fromISOString(dstr[0 .. t]);
immutable tod = TimeOfDay.fromISOString(dstr[t+1 .. $]);
immutable date = Date.fromISOString(str[0 .. t]);
immutable tod = TimeOfDay.fromISOString(str[t+1 .. $]);

return DateTime(date, tod);
}
Expand Down Expand Up @@ -3144,20 +3143,19 @@ public:
if (isSomeString!(S))
{
import std.algorithm.searching : countUntil;
import std.conv : to;
import std.exception : enforce;
import std.format : format;
import std.string : strip;

immutable dstr = to!dstring(strip(isoExtString));
immutable str = strip(isoExtString);

enforce(dstr.length >= 15, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
auto t = dstr.countUntil('T');
enforce(str.length >= 15, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));
auto t = str.countUntil('T');

enforce(t != -1, new DateTimeException(format("Invalid ISO Extended String: %s", isoExtString)));

immutable date = Date.fromISOExtString(dstr[0 .. t]);
immutable tod = TimeOfDay.fromISOExtString(dstr[t+1 .. $]);
immutable date = Date.fromISOExtString(str[0 .. t]);
immutable tod = TimeOfDay.fromISOExtString(str[t+1 .. $]);

return DateTime(date, tod);
}
Expand Down Expand Up @@ -3232,20 +3230,19 @@ public:
if (isSomeString!(S))
{
import std.algorithm.searching : countUntil;
import std.conv : to;
import std.exception : enforce;
import std.format : format;
import std.string : strip;

immutable dstr = to!dstring(strip(simpleString));
immutable str = strip(simpleString);

enforce(dstr.length >= 15, new DateTimeException(format("Invalid string format: %s", simpleString)));
auto t = dstr.countUntil(' ');
enforce(str.length >= 15, new DateTimeException(format("Invalid string format: %s", simpleString)));
auto t = str.countUntil(' ');

enforce(t != -1, new DateTimeException(format("Invalid string format: %s", simpleString)));

immutable date = Date.fromSimpleString(dstr[0 .. t]);
immutable tod = TimeOfDay.fromISOExtString(dstr[t+1 .. $]);
immutable date = Date.fromSimpleString(str[0 .. t]);
immutable tod = TimeOfDay.fromISOExtString(str[t+1 .. $]);

return DateTime(date, tod);
}
Expand Down