From a96aa4de701037477083b99efe290d748bbc8b9b Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 1 Nov 2016 12:48:46 -0600 Subject: [PATCH] qbsp: fix stupid perf bug in BuildSurfaces that I introduced (unnecessary insertions and redundant lookups to a map) --- qbsp/csg4.cc | 23 ++++++++--------------- qbsp/qbsp.hh | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/qbsp/csg4.cc b/qbsp/csg4.cc index 0cf13cc4..9bd9402f 100644 --- a/qbsp/csg4.cc +++ b/qbsp/csg4.cc @@ -377,26 +377,19 @@ visible face. ================== */ surface_t * -BuildSurfaces(std::map &planefaces) +BuildSurfaces(const std::map &planefaces) { - int i; - surface_t *surf, *surfaces; - face_t *face; - - surfaces = NULL; - for (i = 0; i < map.numplanes(); i++) { - if (planefaces[i] == nullptr) - continue; - + surface_t *surfaces = NULL; + for (const auto &entry : planefaces) { /* create a new surface to hold the faces on this plane */ - surf = (surface_t *)AllocMem(SURFACE, 1, true); - surf->planenum = i; + surface_t *surf = (surface_t *)AllocMem(SURFACE, 1, true); + surf->planenum = entry.first; surf->next = surfaces; surfaces = surf; - surf->faces = planefaces[i]; - for (face = surf->faces; face; face = face->next) + surf->faces = entry.second; + for (const face_t *face = surf->faces; face; face = face->next) csgmergefaces++; - + /* Calculate bounding box and flags */ CalcSurfaceInfo(surf); } diff --git a/qbsp/qbsp.hh b/qbsp/qbsp.hh index ae29bb81..160dfc9a 100644 --- a/qbsp/qbsp.hh +++ b/qbsp/qbsp.hh @@ -368,7 +368,7 @@ int PlaneInvEqual(const plane_t *p1, const plane_t *p2); extern int csgmergefaces; // build surfaces is also used by GatherNodeFaces -surface_t *BuildSurfaces(std::map &planefaces); +surface_t *BuildSurfaces(const std::map &planefaces); face_t *NewFaceFromFace(face_t *in); void SplitFace(face_t *in, const plane_t *split, face_t **front, face_t **back); void UpdateFaceSphere(face_t *in);