Fri, 16 May 2014 21:59:03 +0300
- use a faster ID choosing setup, this should work so long as nobody goes to create 17 million objects
src/ldObject.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions |
--- a/src/ldObject.cc Fri May 16 21:31:20 2014 +0300 +++ b/src/ldObject.cc Fri May 16 21:59:03 2014 +0300 @@ -32,7 +32,9 @@ CFGENTRY (Int, defaultLicense, 0); // List of all LDObjects -static QMap<long, LDObjectWeakPtr> g_allObjects; +static QMap<long, LDObjectWeakPtr> g_allObjects; +static int32 g_idcursor = 1; // 0 shalt be null +static constexpr int32 g_maxID = (1 << 24); #define LDOBJ_DEFAULT_CTOR(T,BASE) \ T :: T (LDObjectPtr* selfptr) : \ @@ -77,20 +79,21 @@ // void LDObject::chooseID() { - int32 id = 1; // 0 shalt be null - - for (auto it = g_allObjects.begin(); it != g_allObjects.end(); ++it) + // If this is the first pass we can just use a global ID counter for each + // unique object. Let's nobody goes to create 17 million objects anytime + // soon. + if (g_idcursor < g_maxID) { - LDObjectPtr obj = it->toStrongRef(); - - assert (obj != this); - assert (obj != null); - - if (obj->id() >= id) - id = obj->id() + 1; + setID (g_idcursor++); + return; } - setID (id); + // In case someone does, we cannot really continue execution. We must abort, + // give the user a chance to save their documents though. + critical ("Created too many objects. Execution cannot continue. You have a " + "chance to save any changes to documents, then restart."); + (void) safeToCloseAll(); + exit (0); } // =============================================================================
--- a/src/ldObject.h Fri May 16 21:31:20 2014 +0300 +++ b/src/ldObject.h Fri May 16 21:59:03 2014 +0300 @@ -71,7 +71,7 @@ PROPERTY (public, bool, isDestructed, setDestructed, STOCK_WRITE) PROPERTY (public, LDObjectWeakPtr, parent, setParent, STOCK_WRITE) PROPERTY (public, LDDocument*, document, setDocument, STOCK_WRITE) - PROPERTY (private, int, id, setID, STOCK_WRITE) + PROPERTY (private, int32, id, setID, STOCK_WRITE) PROPERTY (public, int, color, setColor, CUSTOM_WRITE) PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) PROPERTY (private, LDObjectWeakPtr, self, setSelf, STOCK_WRITE)