Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libmtime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
icon-libraries
libmtime
Commits
f3844207
Commit
f3844207
authored
4 years ago
by
Thomas Jahns
Browse files
Options
Downloads
Patches
Plain Diff
Replace looping with direct computation.
parent
77192531
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!5
Intentional change
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mtime_timedelta.c
+15
-30
15 additions, 30 deletions
src/mtime_timedelta.c
with
15 additions
and
30 deletions
src/mtime_timedelta.c
+
15
−
30
View file @
f3844207
...
...
@@ -1760,41 +1760,26 @@ elementwiseScalarMultiplyTimeDelta(struct _timedelta* base_td, int64_t lambda, s
scaled_td
->
sign
=
'+'
;
/* Sign already handled above. Make lambda positive. */
if
(
lambda
<
0
)
lambda
*=
-
1
;
lambda
=
(
int64_t
)(
llabs
(
lambda
));
/* Multiply each element by scalar. */
int64_t
ms_temp
=
lambda
*
base_td
->
ms
;
scaled_td
->
ms
=
(
int
)(
ms_temp
%
NO_OF_MS_IN_A_SECOND
);
int64_t
s_temp
=
lambda
*
base_td
->
second
+
ms_temp
/
NO_OF_MS_IN_A_SECOND
;
scaled_td
->
second
=
(
int
)(
s_temp
%
60
);
scaled_td
->
ms
+=
(
int
)
lambda
*
base_td
->
ms
;
while
(
scaled_td
->
ms
>=
NO_OF_MS_IN_A_SECOND
)
{
scaled_td
->
ms
-=
NO_OF_MS_IN_A_SECOND
;
scaled_td
->
second
+=
1
;
}
scaled_td
->
second
+=
(
int
)
lambda
*
base_td
->
second
;
while
(
scaled_td
->
second
>=
60
)
{
scaled_td
->
second
-=
60
;
scaled_td
->
minute
+=
1
;
}
scaled_td
->
minute
+=
(
int
)
lambda
*
base_td
->
minute
;
while
(
scaled_td
->
minute
>=
60
)
{
scaled_td
->
minute
-=
60
;
scaled_td
->
hour
+=
1
;
}
int64_t
m_temp
=
lambda
*
base_td
->
minute
+
s_temp
/
60
;
scaled_td
->
minute
=
(
int
)(
m_temp
%
60
);
scaled_td
->
hour
+=
(
int
)
lambda
*
base_td
->
hour
;
int64_t
h_temp
=
lambda
*
base_td
->
hour
+
m_temp
/
60
;
scaled_td
->
hour
=
(
int
)(
h_temp
%
NO_OF_HOURS_IN_A_DAY
);
/* Scalar multiplication
can
not give a value in excess of 24 hours. */
if
(
scaled_td
->
hour
>=
NO_OF_HOURS_IN_A_DAY
)
{
/* ERROR: Return on NULL. */
return
NULL
;
}
/* Scalar multiplication
must
not give a value in excess of 24 hours. */
if
(
h_temp
>=
NO_OF_HOURS_IN_A_DAY
)
{
/* ERROR: Return on NULL. */
return
NULL
;
}
scaled_td
->
day
=
0
;
scaled_td
->
month
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Sergey Kosukhin
@m300488
mentioned in commit
2c775510
·
10 months ago
mentioned in commit
2c775510
mentioned in commit 2c775510d11339e3f5cb2e111919f73982859350
Toggle commit list
Sergey Kosukhin
@m300488
mentioned in merge request
!17 (merged)
·
10 months ago
mentioned in merge request
!17 (merged)
mentioned in merge request !17
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment