Skip to content

Commit d86cea3

Browse files
committed
Make indexstoredb_symbol_location_timestamp and indexstoredb_timestamp_of_latest_unit_for_file return nanoseconds instead of seconds
rdar://126581823
1 parent 3d831e9 commit d86cea3

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

Sources/IndexStoreDB/IndexStoreDB.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public final class IndexStoreDB {
451451
}
452452

453453
/// Returns the latest modification date of a unit that contains the given source file.
454-
///
454+
///
455455
/// If no unit containing the given source file exists, returns `nil`.
456456
public func dateOfLatestUnitFor(filePath: String) -> Date? {
457457
let timestamp = filePath.withCString { filePathCString in
@@ -460,7 +460,7 @@ public final class IndexStoreDB {
460460
if timestamp == 0 {
461461
return nil
462462
}
463-
return Date(timeIntervalSince1970: timestamp)
463+
return Date(timeIntervalSince1970: Double(timestamp) / 1_000_000_000)
464464
}
465465
}
466466

Sources/IndexStoreDB/SymbolLocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension SymbolLocation: CustomStringConvertible {
5151
extension SymbolLocation {
5252
internal init(_ loc: indexstoredb_symbol_location_t) {
5353
path = String(cString: indexstoredb_symbol_location_path(loc))
54-
timestamp = Date(timeIntervalSince1970: indexstoredb_symbol_location_timestamp(loc))
54+
timestamp = Date(timeIntervalSince1970: Double(indexstoredb_symbol_location_timestamp(loc)) / 1_000_000_000)
5555
moduleName = String(cString: indexstoredb_symbol_location_module_name(loc))
5656
isSystem = indexstoredb_symbol_location_is_system(loc)
5757
line = Int(indexstoredb_symbol_location_line(loc))

include/CIndexStoreDB/CIndexStoreDB.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ indexstoredb_index_related_symbol_occurrences_by_usr(
320320
_Nonnull indexstoredb_symbol_occurrence_receiver_t);
321321

322322
/// Iterates over all the symbols contained in \p path
323-
///
323+
///
324324
/// The symbol passed to the receiver is only valid for the duration of the
325325
/// receiver call.
326326
INDEXSTOREDB_PUBLIC bool
@@ -375,10 +375,10 @@ INDEXSTOREDB_PUBLIC
375375
const char * _Nonnull
376376
indexstoredb_symbol_location_path(_Nonnull indexstoredb_symbol_location_t);
377377

378-
/// Returns a Unix timestamp (seconds since 1/1/1970) at which the unit file that contains a symbol has last been
378+
/// Returns a Unix timestamp (nanoseconds since 1/1/1970) at which the unit file that contains a symbol has last been
379379
/// modified.
380380
INDEXSTOREDB_PUBLIC
381-
double
381+
uint64_t
382382
indexstoredb_symbol_location_timestamp(_Nonnull indexstoredb_symbol_location_t loc);
383383

384384
/// Returns the module name of the given symbol location.
@@ -577,10 +577,10 @@ indexstoredb_index_unit_tests(
577577
_Nonnull indexstoredb_symbol_occurrence_receiver_t receiver
578578
);
579579

580-
/// Returns a Unix timestamp (seconds since 1/1/1970) of the latest unit that contains the given source file.
581-
///
580+
/// Returns a Unix timestamp (nanoseconds since 1/1/1970) of the latest unit that contains the given source file.
581+
///
582582
/// If no unit containing the given source file exists, returns 0.
583-
INDEXSTOREDB_PUBLIC double
583+
INDEXSTOREDB_PUBLIC uint64_t
584584
indexstoredb_timestamp_of_latest_unit_for_file(
585585
_Nonnull indexstoredb_index_t index,
586586
const char *_Nonnull fileName

lib/CIndexStoreDB/CIndexStoreDB.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,14 @@ indexstoredb_symbol_location_path(indexstoredb_symbol_location_t loc) {
445445
return obj->getPath().getPathString().c_str();
446446
}
447447

448-
double
448+
uint64_t
449449
indexstoredb_symbol_location_timestamp(indexstoredb_symbol_location_t loc) {
450450
auto obj = (SymbolLocation *)loc;
451451
// Up until C++20 the reference date of time_since_epoch is undefined but according to
452452
// https://en.cppreference.com/w/cpp/chrono/system_clock most implementations use Unix Time.
453453
// Since C++20, system_clock is defined to measure time since 1/1/1970.
454454
// We rely on `time_since_epoch` always returning the nanoseconds since 1/1/1970.
455-
auto nanosecondsSinceEpoch = obj->getPath().getModificationTime().time_since_epoch().count();
456-
return static_cast<double>(nanosecondsSinceEpoch) / 1000 / 1000 / 1000;
455+
return obj->getPath().getModificationTime().time_since_epoch().count();
457456
}
458457

459458
const char *
@@ -668,7 +667,7 @@ indexstoredb_index_unit_tests(
668667
});
669668
}
670669

671-
INDEXSTOREDB_PUBLIC double
670+
INDEXSTOREDB_PUBLIC uint64_t
672671
indexstoredb_timestamp_of_latest_unit_for_file(
673672
_Nonnull indexstoredb_index_t index,
674673
const char *_Nonnull fileName
@@ -680,8 +679,7 @@ indexstoredb_timestamp_of_latest_unit_for_file(
680679
// https://en.cppreference.com/w/cpp/chrono/system_clock most implementations use Unix Time.
681680
// Since C++20, system_clock is defined to measure time since 1/1/1970.
682681
// We rely on `time_since_epoch` always returning the nanoseconds since 1/1/1970.
683-
auto nanosecondsSinceEpoch = timePoint->time_since_epoch().count();
684-
return static_cast<double>(nanosecondsSinceEpoch) / 1000 / 1000 / 1000;
682+
return timePoint->time_since_epoch().count();
685683
}
686684
return 0;
687685
}

0 commit comments

Comments
 (0)