Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions src/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,17 @@ export const AppLayout: React.FC = () => {
const currentRailwayData = useStore.getState().railwayData;

// Only trigger if we have data and missing distances
const needsCalc = Object.values(currentRailwayData).some(line =>
line.stations.length > 1 && line.stations[0].distToNext === undefined
);
// ⚑ Bolt: Replaced Object.values.some() with early-breaking for-in loop to prevent large array allocation.
let needsCalc = false;
for (const lineKey in currentRailwayData) {
if (Object.prototype.hasOwnProperty.call(currentRailwayData, lineKey)) {
const line = currentRailwayData[lineKey];
if (line.stations && line.stations.length > 1 && line.stations[0].distToNext === undefined) {
needsCalc = true;
break;
}
}
}

if (needsCalc) {
const showFakeProgress = useStore.getState().showFakeProgress;
Expand Down
35 changes: 26 additions & 9 deletions src/RailRound.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1265,12 +1265,22 @@ const RecordsView = ({ trips, railwayData, setTrips, onEdit, onDelete, onAdd, se
if (isWalk) {
let startName = t.fromId || '';
let endName = t.toId || '';
Object.values(railwayData).forEach(line => {
const s = line.stations.find(st => st.id === t.fromId);
if (s) startName = s.name_ja;
const e = line.stations.find(st => st.id === t.toId);
if (e) endName = e.name_ja;
});
let foundStart = false;
let foundEnd = false;
// ⚑ Bolt: Replaced Object.values(railwayData).forEach with early-breaking for-in loop to prevent large array allocation and unnecessary traversal.
for (const lineKey in railwayData) {
if (!Object.prototype.hasOwnProperty.call(railwayData, lineKey)) continue;
const line = railwayData[lineKey];
if (!foundStart) {
const s = line.stations.find(st => st.id === t.fromId);
if (s) { startName = s.name_ja; foundStart = true; }
}
if (!foundEnd) {
const e = line.stations.find(st => st.id === t.toId);
if (e) { endName = e.name_ja; foundEnd = true; }
}
if (foundStart && foundEnd) break;
}

const isTree = t.walkType === 'tree';
const cls = {
Expand Down Expand Up @@ -1460,9 +1470,16 @@ const StatsView = ({ trips, railwayData, geoData, user, userProfile, segmentGeom
let count = 0;
if (railwayData) {
const uniqueStations = new Set();
Object.values(railwayData).forEach(line => {
if (line.stations) line.stations.forEach(s => uniqueStations.add(s.id));
});
// ⚑ Bolt: Replaced Object.values.forEach and inner map iteration with faster for-in and classic for loop to prevent O(N) array allocation overhead.
for (const lineKey in railwayData) {
if (!Object.prototype.hasOwnProperty.call(railwayData, lineKey)) continue;
const line = railwayData[lineKey];
if (line.stations) {
for (let i = 0; i < line.stations.length; i++) {
uniqueStations.add(line.stations[i].id);
}
}
}
count = uniqueStations.size;
}
return count;
Expand Down
42 changes: 30 additions & 12 deletions src/components/modals/WalkTripEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ export const WalkTripEditor: React.FC = () => {
// Find coordinates for the Bezier curve
let startCoords = null;
let endCoords = null;
Object.values(railwayData).forEach(line => {
const s = line.stations.find(st => st.id === form.fromId);
if (s) startCoords = [s.lng, s.lat];
const e = line.stations.find(st => st.id === form.toId);
if (e) endCoords = [e.lng, e.lat];
});
// ⚑ Bolt: Replaced Object.values.forEach with early-breaking for-in loop.
for (const lineKey in railwayData) {
if (!Object.prototype.hasOwnProperty.call(railwayData, lineKey)) continue;
const line = railwayData[lineKey];
if (!startCoords) {
const s = line.stations.find(st => st.id === form.fromId);
if (s) startCoords = [s.lng, s.lat];
}
if (!endCoords) {
const e = line.stations.find(st => st.id === form.toId);
if (e) endCoords = [e.lng, e.lat];
}
if (startCoords && endCoords) break;
}

if (startCoords && endCoords) {
walkPath = generateBezierPath(startCoords as [number, number], endCoords as [number, number]);
Expand Down Expand Up @@ -127,12 +135,22 @@ export const WalkTripEditor: React.FC = () => {
// Resolving station names for read-only display
let startName = t('walk.unknownStart', "ζœͺηŸ₯θ΅·η‚Ή");
let endName = t('walk.unknownEnd', "ζœͺηŸ₯η»ˆη‚Ή");
Object.values(railwayData).forEach(line => {
const s = line.stations.find(st => st.id === form.fromId);
if (s) startName = s.name_ja;
const e = line.stations.find(st => st.id === form.toId);
if (e) endName = e.name_ja;
});
let foundStart = false;
let foundEnd = false;
// ⚑ Bolt: Replaced Object.values.forEach with early-breaking for-in loop to prevent large array allocation.
for (const lineKey in railwayData) {
if (!Object.prototype.hasOwnProperty.call(railwayData, lineKey)) continue;
const line = railwayData[lineKey];
if (!foundStart) {
const s = line.stations.find(st => st.id === form.fromId);
if (s) { startName = s.name_ja; foundStart = true; }
}
if (!foundEnd) {
const e = line.stations.find(st => st.id === form.toId);
if (e) { endName = e.name_ja; foundEnd = true; }
}
if (foundStart && foundEnd) break;
}

const isTree = form.walkType === 'tree';

Expand Down
22 changes: 16 additions & 6 deletions src/pages/TripsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,22 @@ export const TripsPage: React.FC = () => {
if (isWalk) {
let startName = trip.fromId || '';
let endName = trip.toId || '';
Object.values(railwayData).forEach(line => {
const s = line.stations.find(st => st.id === trip.fromId);
if (s) startName = s.name_ja;
const e = line.stations.find(st => st.id === trip.toId);
if (e) endName = e.name_ja;
});
let foundStart = false;
let foundEnd = false;
// ⚑ Bolt: Replaced Object.values.forEach with early-breaking for-in loop to avoid allocating large arrays.
for (const lineKey in railwayData) {
if (!Object.prototype.hasOwnProperty.call(railwayData, lineKey)) continue;
const line = railwayData[lineKey];
if (!foundStart) {
const s = line.stations.find(st => st.id === trip.fromId);
if (s) { startName = s.name_ja; foundStart = true; }
}
if (!foundEnd) {
const e = line.stations.find(st => st.id === trip.toId);
if (e) { endName = e.name_ja; foundEnd = true; }
}
if (foundStart && foundEnd) break;
}

const isTree = trip.walkType === 'tree';
const cls = {
Expand Down