Skip to content

Commit

Permalink
Avoid unnecessary pointer params for gmtime/localtime. NFC (#19698)
Browse files Browse the repository at this point in the history
Seems like there is no reason to pass a pointer here.

I noticed this while investigating #19694.
  • Loading branch information
sbc100 committed Jun 23, 2023
1 parent 53a9937 commit 01f13eb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,10 @@ mergeInto(LibraryManager.library, {
return (date.getTime() / 1000)|0;
},
_gmtime_js__deps: ['$readI53FromI64'],
_gmtime_js: (time, tmPtr) => {
var date = new Date({{{ makeGetValue('time', 0, 'i53') }}}*1000);
_gmtime_js__deps: ['$readI53FromI64'].concat(i53ConversionDeps),
_gmtime_js: ({{{ defineI64Param('time') }}}, tmPtr) => {
{{{ receiveI64ParamAsI53('time') }}}
var date = new Date(time * 1000);
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_sec, 'date.getUTCSeconds()', 'i32') }}};
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_min, 'date.getUTCMinutes()', 'i32') }}};
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_hour, 'date.getUTCHours()', 'i32') }}};
Expand Down Expand Up @@ -512,9 +513,10 @@ mergeInto(LibraryManager.library, {
return (date.getTime() / 1000)|0;
},
_localtime_js__deps: ['$readI53FromI64', '$ydayFromDate'],
_localtime_js: (time, tmPtr) => {
var date = new Date({{{ makeGetValue('time', 0, 'i53') }}}*1000);
_localtime_js__deps: ['$readI53FromI64', '$ydayFromDate'].concat(i53ConversionDeps),
_localtime_js: ({{{ defineI64Param('time') }}}, tmPtr) => {
{{{ receiveI64ParamAsI53('time') }}}
var date = new Date(time*1000);
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_sec, 'date.getSeconds()', 'i32') }}};
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_min, 'date.getMinutes()', 'i32') }}};
{{{ makeSetValue('tmPtr', C_STRUCTS.tm.tm_hour, 'date.getHours()', 'i32') }}};
Expand Down
4 changes: 2 additions & 2 deletions src/library_sigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ sigs = {
_emval_take_value__sig: 'ppp',
_emval_throw__sig: 'ip',
_emval_typeof__sig: 'pp',
_gmtime_js__sig: 'vpp',
_localtime_js__sig: 'vpp',
_gmtime_js__sig: 'vjp',
_localtime_js__sig: 'vjp',
_mktime_js__sig: 'ip',
_mmap_js__sig: 'ipiiijpp',
_msync_js__sig: 'ippiiij',
Expand Down
2 changes: 1 addition & 1 deletion src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ global.LibraryManager = {

// Core system libraries (always linked against)
let libraries = [
'library_int53.js',
'library.js',
'library_sigs.js',
'library_int53.js',
'library_ccall.js',
'library_addfunction.js',
'library_formatString.js',
Expand Down
4 changes: 2 additions & 2 deletions system/lib/libc/emscripten_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void emscripten_notify_memory_growth(size_t memory_index);
// TODO(sbc): Covert back to `time_t` before 2038 ...
int _timegm_js(struct tm* tm);
int _mktime_js(struct tm* tm);
void _localtime_js(const time_t* __restrict__ t, struct tm* __restrict__ tm);
void _gmtime_js(const time_t* __restrict__ t, struct tm* __restrict__ tm);
void _localtime_js(time_t t, struct tm* __restrict__ tm);
void _gmtime_js(time_t t, struct tm* __restrict__ tm);

void _tzset_js(long* timezone, int* daylight, char** tzname);

Expand Down
4 changes: 2 additions & 2 deletions system/lib/libc/mktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ weak time_t mktime(struct tm *tm) {

weak struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm) {
tzset();
_localtime_js(t, tm);
_localtime_js(*t, tm);
// __localtime_js sets everything but the tmzone pointer
tm->__tm_zone = tm->tm_isdst ? tzname[1] :tzname[0];
return tm;
}

weak struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) {
tzset();
_gmtime_js(t, tm);
_gmtime_js(*t, tm);
tm->tm_isdst = 0;
tm->__tm_gmtoff = 0;
tm->__tm_zone = "GMT";
Expand Down

0 comments on commit 01f13eb

Please sign in to comment.