Skip to content

Commit 244c045

Browse files
committed
stash
1 parent 8b855f3 commit 244c045

11 files changed

Lines changed: 209 additions & 281 deletions

runtime-light/stdlib/time/dateinterval.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
#include "runtime-light/stdlib/diagnostics/exception-functions.h"
1414
#include "runtime-light/stdlib/diagnostics/logs.h"
1515

16-
C$DateInterval::~C$DateInterval() {
17-
if (rel_time != nullptr) {
18-
kphp::timelib::destruct(rel_time);
19-
rel_time = nullptr;
20-
}
21-
}
22-
2316
class_instance<C$DateInterval> f$DateInterval$$__construct(const class_instance<C$DateInterval>& self, const string& duration) noexcept {
2417
auto expected_rel_time{kphp::timelib::construct_interval({duration.c_str(), duration.size()})};
2518
if (!expected_rel_time.has_value()) [[unlikely]] {
@@ -28,7 +21,7 @@ class_instance<C$DateInterval> f$DateInterval$$__construct(const class_instance<
2821
THROW_EXCEPTION(kphp::exception::make_throwable<C$Exception>(err_msg));
2922
return {};
3023
}
31-
self->rel_time = *expected_rel_time;
24+
self->rel_time = std::move(*expected_rel_time);
3225
return self;
3326
}
3427

@@ -38,16 +31,15 @@ class_instance<C$DateInterval> f$DateInterval$$createFromDateString(const string
3831
kphp::log::warning("DateInterval::createFromDateString(): failed to parse datetime ({}): {}", datetime.c_str(), expected_time.error());
3932
return {};
4033
}
41-
timelib_time* time{*expected_time};
42-
vk::final_action time_deleter{[time] { kphp::timelib::destruct(time); }};
34+
kphp::timelib::time_t time{std::move(*expected_time)};
4335
class_instance<C$DateInterval> date_interval;
4436
date_interval.alloc();
45-
date_interval->rel_time = kphp::timelib::clone(std::addressof(time->relative));
37+
date_interval->rel_time = kphp::timelib::clone(time->relative);
4638
return date_interval;
4739
}
4840

4941
string f$DateInterval$$format(const class_instance<C$DateInterval>& self, const string& format) noexcept {
5042
string str;
51-
kphp::timelib::date_interval_format_to(std::back_inserter(str), {format.c_str(), format.size()}, self->rel_time);
43+
kphp::timelib::date_interval_format_to(std::back_inserter(str), {format.c_str(), format.size()}, *self->rel_time);
5244
return str;
5345
}

runtime-light/stdlib/time/dateinterval.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
struct C$DateInterval : public refcountable_polymorphic_php_classes_virt<>, private DummyVisitorMethods {
1717
using DummyVisitorMethods::accept;
1818

19-
timelib_rel_time* rel_time{nullptr};
19+
kphp::timelib::rel_time_t rel_time{nullptr};
2020

2121
virtual const char* get_class() const noexcept {
2222
return R"(DateInterval)";
@@ -26,8 +26,6 @@ struct C$DateInterval : public refcountable_polymorphic_php_classes_virt<>, priv
2626
std::string_view name_view{C$DateInterval::get_class()};
2727
return static_cast<int32_t>(vk::murmur_hash<uint32_t>(name_view.data(), name_view.size()));
2828
}
29-
30-
~C$DateInterval() override;
3129
};
3230

3331
class_instance<C$DateInterval> f$DateInterval$$__construct(const class_instance<C$DateInterval>& self, const string& duration) noexcept;

runtime-light/stdlib/time/datetime.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
#include "runtime-light/stdlib/diagnostics/exception-functions.h"
88
#include "runtime-light/stdlib/time/timelib-functions.h"
99

10-
C$DateTime::~C$DateTime() {
11-
if (time != nullptr) {
12-
kphp::timelib::destruct(time);
13-
time = nullptr;
14-
}
15-
}
16-
1710
class_instance<C$DateTime> f$DateTime$$__construct(const class_instance<C$DateTime>& self, const string& datetime,
1811
const class_instance<C$DateTimeZone>& timezone) noexcept {
1912
const auto& str_to_parse{datetime.empty() ? StringLibConstants::get().NOW_STR : datetime};
@@ -24,7 +17,7 @@ class_instance<C$DateTime> f$DateTime$$__construct(const class_instance<C$DateTi
2417
THROW_EXCEPTION(kphp::exception::make_throwable<C$Exception>(err_msg));
2518
}
2619

27-
timelib_time* time{*expected_time};
20+
kphp::timelib::time_t time{std::move(*expected_time)};
2821
timelib_tzinfo* tzi{!timezone.is_null() ? timezone->tzi : nullptr};
2922
if (tzi == nullptr) {
3023
if (time->tz_info != nullptr) {
@@ -34,8 +27,8 @@ class_instance<C$DateTime> f$DateTime$$__construct(const class_instance<C$DateTi
3427
}
3528
}
3629

37-
kphp::timelib::fill_holes(time, tzi);
30+
kphp::timelib::fill_holes_with_now(*time, tzi);
3831

39-
self->time = time;
32+
self->time = std::move(time);
4033
return self;
4134
}

runtime-light/stdlib/time/datetime.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ struct C$DateTime : public C$DateTimeInterface, private DummyVisitorMethods {
2727
std::string_view name_view{C$DateTime::get_class()};
2828
return static_cast<int32_t>(vk::murmur_hash<uint32_t>(name_view.data(), name_view.size()));
2929
}
30-
31-
~C$DateTime() override;
3230
};
3331

3432
class_instance<C$DateTime> f$DateTime$$__construct(const class_instance<C$DateTime>& self, const string& datetime = StringLibConstants::get().NOW_STR,

runtime-light/stdlib/time/datetimeimmutable.cpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,12 @@ namespace {
2727
class_instance<C$DateTimeImmutable> clone_immutable(const class_instance<C$DateTimeImmutable>& origin) noexcept {
2828
class_instance<C$DateTimeImmutable> clone;
2929
clone.alloc();
30-
clone->time = kphp::timelib::clone(origin->time);
30+
clone->time = kphp::timelib::clone(*origin->time);
3131
return clone;
3232
}
3333

3434
} // namespace
3535

36-
C$DateTimeImmutable::~C$DateTimeImmutable() {
37-
if (time != nullptr) {
38-
kphp::timelib::destruct(time);
39-
time = nullptr;
40-
}
41-
}
42-
4336
class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$__construct(const class_instance<C$DateTimeImmutable>& self, const string& datetime,
4437
const class_instance<C$DateTimeZone>& timezone) noexcept {
4538
const auto& str_to_parse{datetime.empty() ? StringLibConstants::get().NOW_STR : datetime};
@@ -50,7 +43,7 @@ class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$__construct(const class
5043
THROW_EXCEPTION(kphp::exception::make_throwable<C$Exception>(err_msg));
5144
}
5245

53-
timelib_time* time{*expected_time};
46+
kphp::timelib::time_t time{std::move(*expected_time)};
5447
timelib_tzinfo* tzi{!timezone.is_null() ? timezone->tzi : nullptr};
5548
if (tzi == nullptr) {
5649
if (time->tz_info != nullptr) {
@@ -60,16 +53,16 @@ class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$__construct(const class
6053
}
6154
}
6255

63-
kphp::timelib::fill_holes(time, tzi);
56+
kphp::timelib::fill_holes_with_now(*time, tzi);
6457

65-
self->time = time;
58+
self->time = std::move(time);
6659
return self;
6760
}
6861

6962
class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$add(const class_instance<C$DateTimeImmutable>& self,
7063
const class_instance<C$DateInterval>& interval) noexcept {
71-
auto new_date = clone_immutable(self);
72-
new_date->time = kphp::timelib::add(new_date->time, interval->rel_time);
64+
auto new_date{clone_immutable(self)};
65+
new_date->time = kphp::timelib::add(*new_date->time, *interval->rel_time);
7366
return new_date;
7467
}
7568

@@ -82,31 +75,31 @@ class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$createFromFormat(const
8275
auto time{std::move(*expected_time)};
8376
timelib_tzinfo* tzi{!timezone.is_null() ? timezone->tzi : nullptr};
8477
if (tzi == nullptr) {
85-
if (time.tz_info != nullptr) {
86-
tzi = time.tz_info;
78+
if (time->tz_info != nullptr) {
79+
tzi = time->tz_info;
8780
} else if (auto* default_tzi{kphp::timelib::get_timezone_info(TimeInstanceState::get().default_timezone.c_str())}; default_tzi != nullptr) {
8881
tzi = default_tzi;
8982
}
9083
}
9184

92-
kphp::timelib::fill_holes<true>(time, tzi);
85+
kphp::timelib::fill_holes_with_now<true>(*time, tzi);
9386

9487
class_instance<C$DateTimeImmutable> date_time;
9588
date_time.alloc();
96-
date_time->time = time;
89+
date_time->time = std::move(time);
9790
return date_time;
9891
}
9992

10093
class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$createFromMutable(const class_instance<C$DateTime>& object) noexcept {
10194
class_instance<C$DateTimeImmutable> clone;
10295
clone.alloc();
103-
clone->time = kphp::timelib::clone(object->time);
96+
clone->time = kphp::timelib::clone(*object->time);
10497
return clone;
10598
}
10699

107100
class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$modify(const class_instance<C$DateTimeImmutable>& self, const string& modifier) noexcept {
108-
auto new_date = clone_immutable(self);
109-
auto expected_success = kphp::timelib::modify(new_date->time, {modifier.c_str(), modifier.size()});
101+
auto new_date{clone_immutable(self)};
102+
auto expected_success{kphp::timelib::modify(*new_date->time, {modifier.c_str(), modifier.size()})};
110103
if (!expected_success.has_value()) [[unlikely]] {
111104
kphp::log::warning("DateTimeImmutable::modify(): failed to parse modifier ({}): {}", modifier.c_str(), expected_success.error());
112105
return {};
@@ -115,22 +108,22 @@ class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$modify(const class_inst
115108
}
116109

117110
class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$setTimestamp(const class_instance<C$DateTimeImmutable>& self, int64_t timestamp) noexcept {
118-
auto new_date = clone_immutable(self);
119-
kphp::timelib::date_timestamp_set(new_date->time, timestamp);
111+
auto new_date{clone_immutable(self)};
112+
kphp::timelib::date_timestamp_set(*new_date->time, timestamp);
120113
return new_date;
121114
}
122115

123116
class_instance<C$DateInterval> f$DateTimeImmutable$$diff(const class_instance<C$DateTimeImmutable>& self,
124117
const class_instance<C$DateTimeInterface>& target_object, bool absolute) noexcept {
125118
class_instance<C$DateInterval> interval;
126119
interval.alloc();
127-
interval->rel_time = kphp::timelib::date_diff(self->time, target_object.get()->time, absolute);
120+
interval->rel_time = kphp::timelib::date_diff(*self->time, *target_object.get()->time, absolute);
128121
return interval;
129122
}
130123

131124
string f$DateTimeImmutable$$format(const class_instance<C$DateTimeImmutable>& self, const string& format) noexcept {
132125
string str;
133-
kphp::timelib::date_format_to_localtime(std::back_inserter(str), {format.c_str(), format.size()}, self->time);
126+
kphp::timelib::date_format_to_localtime(std::back_inserter(str), {format.c_str(), format.size()}, *self->time);
134127
return str;
135128
}
136129

runtime-light/stdlib/time/datetimeimmutable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ struct C$DateTimeImmutable : public C$DateTimeInterface, private DummyVisitorMet
2828
std::string_view name_view{C$DateTimeImmutable::get_class()};
2929
return static_cast<int32_t>(vk::murmur_hash<uint32_t>(name_view.data(), name_view.size()));
3030
}
31-
32-
~C$DateTimeImmutable() override;
3331
};
3432

3533
class_instance<C$DateTimeImmutable> f$DateTimeImmutable$$__construct(const class_instance<C$DateTimeImmutable>& self,

runtime-light/stdlib/time/datetimeinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ struct C$DateTimeInterface : public refcountable_polymorphic_php_classes_virt<>
1313
kphp::timelib::time_t time{nullptr};
1414

1515
virtual const char* get_class() const noexcept = 0;
16-
virtual int get_hash() const noexcept = 0;
16+
virtual int32_t get_hash() const noexcept = 0;
1717
};

runtime-light/stdlib/time/time-functions.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace {
1818

1919
constexpr std::array<std::string_view, 4> suffix = {"st", "nd", "rd", "th"};
2020

21-
void iso_week_number(int y, int doy, int weekday, int& iw, int& iy) noexcept {
22-
int y_leap = std::chrono::year(y).is_leap();
23-
int prev_y_leap = std::chrono::year(y - 1).is_leap();
24-
int jan1weekday = (weekday - (doy % 7) + 7) % 7;
21+
void iso_week_number(int32_t y, int32_t doy, int32_t weekday, int32_t& iw, int32_t& iy) noexcept {
22+
auto y_leap{std::chrono::year(y).is_leap()};
23+
auto prev_y_leap{std::chrono::year(y - 1).is_leap()};
24+
auto jan1weekday{(weekday - (doy % 7) + 7) % 7};
2525

2626
if (weekday == 0) {
2727
weekday = 7;
@@ -42,7 +42,7 @@ void iso_week_number(int y, int doy, int weekday, int& iw, int& iy) noexcept {
4242
}
4343
/* Find if Y M D falls in YearNumber Y+1, WeekNumber 1 */
4444
if (iy == y) {
45-
int i = y_leap ? 366 : 365;
45+
auto i{y_leap ? 366 : 365};
4646
if ((i - (doy - y_leap + 1)) < (4 - weekday)) {
4747
iy = y + 1;
4848
iw = 1;
@@ -51,7 +51,7 @@ void iso_week_number(int y, int doy, int weekday, int& iw, int& iy) noexcept {
5151
}
5252
/* Find if Y M D falls in YearNumber Y, WeekNumber 1 through 53 */
5353
if (iy == y) {
54-
int j = doy + (7 - weekday) + jan1weekday;
54+
auto j{doy + (7 - weekday) + jan1weekday};
5555
iw = j / 7;
5656
if (jan1weekday > 4) {
5757
iw -= 1;
@@ -77,21 +77,21 @@ int64_t fix_year(int64_t year) noexcept {
7777
string date(const string& format, const tm& t, int64_t timestamp, bool local) noexcept {
7878
string_buffer& SB{RuntimeContext::get().static_SB};
7979

80-
int year = t.tm_year + 1900;
81-
int month = t.tm_mon + 1;
82-
int day = t.tm_mday;
83-
int hour = t.tm_hour;
84-
int hour12 = (hour + 11) % 12 + 1;
85-
int minute = t.tm_min;
86-
int second = t.tm_sec;
87-
int day_of_week = t.tm_wday;
88-
int day_of_year = t.tm_yday;
89-
int64_t internet_time = 0;
90-
int iso_week = 0;
91-
int iso_year = 0;
80+
auto year{t.tm_year + 1900};
81+
auto month{t.tm_mon + 1};
82+
auto day{t.tm_mday};
83+
auto hour{t.tm_hour};
84+
auto hour12{(hour + 11) % 12 + 1};
85+
auto minute{t.tm_min};
86+
auto second{t.tm_sec};
87+
auto day_of_week{t.tm_wday};
88+
auto day_of_year{t.tm_yday};
89+
int64_t internet_time{0};
90+
auto iso_week{0};
91+
auto iso_year{0};
9292

9393
SB.clean();
94-
for (int i = 0; i < static_cast<int>(format.size()); i++) {
94+
for (auto i{0}; i < format.size(); i++) {
9595
switch (format[i]) {
9696
case 'd':
9797
SB << static_cast<char>(day / 10 + '0') << static_cast<char>(day % 10 + '0');
@@ -109,7 +109,7 @@ string date(const string& format, const tm& t, int64_t timestamp, bool local) no
109109
SB << (day_of_week == 0 ? '7' : static_cast<char>(day_of_week + '0'));
110110
break;
111111
case 'S': {
112-
int c = INT_MAX;
112+
auto c{INT_MAX};
113113
switch (day) {
114114
case 1:
115115
case 21:
@@ -157,7 +157,7 @@ string date(const string& format, const tm& t, int64_t timestamp, bool local) no
157157
std::chrono::year_month_day_last(std::chrono::year(year), std::chrono::month_day_last{std::chrono::month(month) / std::chrono::last}).day());
158158
break;
159159
case 'L':
160-
SB << static_cast<int>(std::chrono::year(year).is_leap());
160+
SB << static_cast<int32_t>(std::chrono::year(year).is_leap());
161161
break;
162162
case 'o':
163163
iso_week_number(year, day_of_year, day_of_week, iso_week, iso_year);
@@ -211,7 +211,7 @@ string date(const string& format, const tm& t, int64_t timestamp, bool local) no
211211
}
212212
break;
213213
case 'I':
214-
SB << static_cast<int>(t.tm_isdst > 0);
214+
SB << static_cast<int32_t>(t.tm_isdst > 0);
215215
break;
216216
case 'O':
217217
if (local) {

runtime-light/stdlib/time/time-functions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
namespace kphp::time::impl {
2222

23-
constexpr inline int64_t CHECKDATE_YEAR_MIN = 1;
24-
constexpr inline int64_t CHECKDATE_YEAR_MAX = 32767;
23+
constexpr inline int64_t CHECKDATE_YEAR_MIN{1};
24+
constexpr inline int64_t CHECKDATE_YEAR_MAX{32767};
2525

2626
int64_t fix_year(int64_t year) noexcept;
2727

@@ -49,7 +49,7 @@ inline string f$_microtime_string() noexcept {
4949
const auto seconds{duration_cast<chrono::seconds>(time_since_epoch).count()};
5050
const auto nanoseconds{duration_cast<chrono::nanoseconds>(time_since_epoch).count() % 1'000'000'000};
5151

52-
static constexpr size_t default_buffer_size = 60;
52+
static constexpr size_t default_buffer_size{60};
5353
char buf[default_buffer_size];
5454
const auto len{snprintf(buf, default_buffer_size, "0.%09lld %lld", nanoseconds, seconds)};
5555
return {buf, static_cast<string::size_type>(len)};

0 commit comments

Comments
 (0)