aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-07-09 12:08:54 +0200
committerGitHub <noreply@github.com>2019-07-09 12:08:54 +0200
commit06af88cd72eaf429190678dcd6d500122e35f349 (patch)
tree827c969ae10a15ff59bbd6f43dc23a7a74520378
parent652be3cb0040d37d295ca9389d72dc8dce0b56fc (diff)
downloadrneovim-06af88cd72eaf429190678dcd6d500122e35f349.tar.gz
rneovim-06af88cd72eaf429190678dcd6d500122e35f349.tar.bz2
rneovim-06af88cd72eaf429190678dcd6d500122e35f349.zip
viml/reltime(): allow negative result #10453
- define proftime_T as signed integer - profile_sub(): allow negative result closes #10452
-rw-r--r--src/nvim/os/time.c6
-rw-r--r--src/nvim/profile.c4
-rw-r--r--src/nvim/profile.h2
-rw-r--r--test/functional/eval/reltime_spec.lua10
4 files changed, 16 insertions, 6 deletions
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index 18239c5566..1094fbc946 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -39,7 +39,7 @@ void time_init(void)
/// @see gettimeofday(2)
///
/// @return Current time in microseconds.
-uint64_t os_utime(void)
+int64_t os_utime(void)
FUNC_ATTR_WARN_UNUSED_RESULT
{
uv_timeval64_t tm;
@@ -47,8 +47,8 @@ uint64_t os_utime(void)
if (e != 0 || tm.tv_sec < 0 || tm.tv_usec < 0) {
return 0;
}
- uint64_t rv = (uint64_t)tm.tv_sec * 1000 * 1000; // s => μs
- STRICT_ADD(rv, tm.tv_usec, &rv, uint64_t);
+ int64_t rv = tm.tv_sec * 1000 * 1000; // s => μs
+ STRICT_ADD(rv, tm.tv_usec, &rv, int64_t);
return rv;
}
diff --git a/src/nvim/profile.c b/src/nvim/profile.c
index cc12e00396..ae3f1d9b5e 100644
--- a/src/nvim/profile.c
+++ b/src/nvim/profile.c
@@ -61,7 +61,7 @@ proftime_T profile_setlimit(int64_t msec) FUNC_ATTR_WARN_UNUSED_RESULT
}
assert(msec <= (INT64_MAX / 1000LL) - 1);
- proftime_T usec = (proftime_T)msec * 1000ULL;
+ proftime_T usec = msec * 1000;
return os_utime() + usec;
}
@@ -111,7 +111,7 @@ proftime_T profile_add(proftime_T tm1, proftime_T tm2) FUNC_ATTR_CONST
/// @return `tm1` - `tm2`
proftime_T profile_sub(proftime_T tm1, proftime_T tm2) FUNC_ATTR_CONST
{
- return tm1 > tm2 ? tm1 - tm2 : 0; // os_utime() may go backwards.
+ return tm1 - tm2;
}
/// Adds the `self` time from the total time and the `children` time.
diff --git a/src/nvim/profile.h b/src/nvim/profile.h
index 7b378577ce..2608514313 100644
--- a/src/nvim/profile.h
+++ b/src/nvim/profile.h
@@ -4,7 +4,7 @@
#include <stdint.h>
#include <time.h>
-typedef uint64_t proftime_T;
+typedef int64_t proftime_T;
#define TIME_MSG(s) do { \
if (time_fd != NULL) time_msg(s, NULL); \
diff --git a/test/functional/eval/reltime_spec.lua b/test/functional/eval/reltime_spec.lua
index 0181f09024..ef7a3a148f 100644
--- a/test/functional/eval/reltime_spec.lua
+++ b/test/functional/eval/reltime_spec.lua
@@ -33,4 +33,14 @@ describe('reltimestr(), reltimefloat()', function()
ok(reltimefloat(differs) < 1.0)
end)
+
+ it('reltime() allows negative result #10452', function()
+ local older_time = reltime()
+ command('sleep 1m')
+ local newer_time = reltime()
+ -- Should be something like -0.002123.
+ local rv = tonumber(reltimestr(reltime(newer_time, older_time)))
+ ok(rv < 0)
+ ok(rv > -10)
+ end)
end)