# HG changeset patch # User Santeri Piippo # Date 1401375283 -10800 # Node ID aa823ba3241dc210efea095bf978e21fa9b65e4a # Parent b0d84fb70ea5806e18cdbc776c58dec98e2f13c1 - when saving, prepare the data first into a buffer and then write to disk, minimizing the time needed to perform the I/O operation. diff -r b0d84fb70ea5 -r aa823ba3241d src/ldDocument.cc --- a/src/ldDocument.cc Thu May 22 18:01:19 2014 +0300 +++ b/src/ldDocument.cc Thu May 29 17:54:43 2014 +0300 @@ -725,19 +725,16 @@ // bool LDDocument::save (String savepath) { + if (isImplicit()) + return false; + if (not savepath.length()) savepath = fullPath(); - QFile f (savepath); - - if (not f.open (QIODevice::WriteOnly)) - return false; - // If the second object in the list holds the file name, update that now. - // Only do this if the file is explicitly open. LDObjectPtr nameObject = getObject (1); - if (not isImplicit() && nameObject != null && nameObject->type() == LDObject::EComment) + if (nameObject != null && nameObject->type() == LDObject::EComment) { LDCommentPtr nameComment = nameObject.staticCast(); @@ -749,12 +746,19 @@ } } + QByteArray data; + // File is open, now save the model to it. Note that LDraw requires files to // have DOS line endings, so we terminate the lines with \r\n. for (LDObjectPtr obj : objects()) - f.write ((obj->asText() + "\r\n").toUtf8()); + data.append ((obj->asText() + "\r\n").toUtf8()); + + QFile f (savepath); - // File is saved, now clean up. + if (not f.open (QIODevice::WriteOnly)) + return false; + + f.write (data); f.close(); // We have successfully saved, update the save position now.