Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #98 - Reuse Calendar for creating ServiceDate in WSFBlockResolutionStrategy #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private void setBlockIdsFromSchedResponse(SchedResponse resp) {
String arrive = stc.getArrivingTerminalID().toString();

for (SchedTime sched : schedTime(stc)) {
long time = ts(sched.getDepartingTime());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdjacobs I think the optimization is here - if you look at private long ts(XMLGregorianCalendar xgc) {...} method, within that method it instantiates a GregorianCalendar to get the time, but then throws it away and just returns a long. Then, in resolve() another Calendar object is instantiated again. This cuts out the instatiation in resolve() by passing in an existing instance of Calendar into resolve().

@skjolber Did I get that right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barbeau Yes.

Trip trip = _tripResolutionService.resolve(depart, time, arrive);
GregorianCalendar gregorianCalendar = sched.getDepartingTime().toGregorianCalendar(_agencyTimeZone, null, null);
Trip trip = _tripResolutionService.resolve(depart, gregorianCalendar, arrive);
if (trip != null) {
trip.setBlockId(sched.getVesselID().toString());
} else {
Expand Down Expand Up @@ -278,10 +278,9 @@ public WSFTripResolutionService(GtfsRelationalDao dao, String agencyId,
_maxStopTime = calculateMaxStopTime();
}

public Trip resolve(String departingTerminalId, long departureTime,
public Trip resolve(String departingTerminalId, Calendar departureTime,
String arrivingTerminalId) {
ServiceDate initialServiceDate = new ServiceDate(
new Date(departureTime * 1000));
ServiceDate initialServiceDate = new ServiceDate(departureTime);
int lookBackDays = (_maxStopTime / 86400) + 1;

AgencyAndId stopId = new AgencyAndId(_agencyId, departingTerminalId);
Expand All @@ -297,9 +296,9 @@ public Trip resolve(String departingTerminalId, long departureTime,

if (_csd.getServiceIdsForDate(sd).contains(
st.getTrip().getServiceId())
&& st.getDepartureTime() == (departureTime
- (sd.getAsCalendar(_agencyTimeZone).getTimeInMillis()
/ 1000))) {
&& st.getDepartureTime() == (departureTime.getTimeInMillis()
- sd.getAsCalendar(_agencyTimeZone).getTimeInMillis())
/ 1000) {

return st.getTrip();
}
Expand Down