Skip to content

Commit

Permalink
Introjucer saving optimisations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Storer committed Aug 13, 2011
1 parent e7ca796 commit d3bcbee
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 57 deletions.
19 changes: 10 additions & 9 deletions extras/Introjucer/Source/Project/jucer_JuceLibraryModule.h
Expand Up @@ -133,6 +133,8 @@ class JuceLibraryModule : public LibraryModule
File moduleFile, moduleFolder;

private:
mutable Array<File> sourceFiles;

File getInclude() const
{
return moduleFolder.getChildFile (moduleInfo ["include"]);
Expand Down Expand Up @@ -171,11 +173,10 @@ class JuceLibraryModule : public LibraryModule

Array<File> tempList;

FileSorter sorter;
while (iter.next())
tempList.add (iter.getFile());
tempList.addSorted (sorter, iter.getFile());

FileSorter sorter;
tempList.sort (sorter);
result.addArray (tempList);
}

Expand All @@ -202,7 +203,7 @@ class JuceLibraryModule : public LibraryModule
else
{
if (! group.findItemForFile (file).isValid())
group.addFile (file, -1, false);
group.addFileUnchecked (file, -1, false);
}
}

Expand Down Expand Up @@ -255,15 +256,15 @@ class JuceLibraryModule : public LibraryModule

void addIncludedCode (ProjectExporter& exporter, const Array<File>& compiled) const
{
Array<File> files;
getAllSourceFiles (files);
if (sourceFiles.size() == 0)
getAllSourceFiles (sourceFiles);

Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID()));

int i;
for (i = 0; i < files.size(); ++i)
addFileWithGroups (sourceGroup, files.getReference(i),
files.getReference(i).getRelativePathFrom (moduleFolder));
for (i = 0; i < sourceFiles.size(); ++i)
addFileWithGroups (sourceGroup, sourceFiles.getReference(i),
sourceFiles.getReference(i).getRelativePathFrom (moduleFolder));

sourceGroup.addFile (moduleFile, -1, false);
sourceGroup.addFile (getInclude(), -1, false);
Expand Down
37 changes: 24 additions & 13 deletions extras/Introjucer/Source/Project/jucer_Project.cpp
Expand Up @@ -716,19 +716,7 @@ bool Project::Item::addFile (const File& file, int insertIndex, const bool shoul
else if (file.existsAsFile())
{
if (! getProject().getMainGroup().findItemForFile (file).isValid())
{
Item item (getProject(), ValueTree (Tags::file));
item.initialiseNodeValues();
item.getName() = file.getFileName();
item.getShouldCompileValue() = shouldCompile && file.hasFileExtension ("cpp;mm;c;m;cc;cxx;r");
item.getShouldAddToResourceValue() = getProject().shouldBeAddedToBinaryResourcesByDefault (file);

if (canContain (item))
{
item.setFile (file);
addChild (item, insertIndex);
}
}
addFileUnchecked (file, insertIndex, shouldCompile);
}
else
{
Expand All @@ -738,6 +726,21 @@ bool Project::Item::addFile (const File& file, int insertIndex, const bool shoul
return true;
}

void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
{
Item item (getProject(), ValueTree (Tags::file));
item.initialiseNodeValues();
item.getName() = file.getFileName();
item.getShouldCompileValue() = shouldCompile && file.hasFileExtension ("cpp;mm;c;m;cc;cxx;r");
item.getShouldAddToResourceValue() = getProject().shouldBeAddedToBinaryResourcesByDefault (file);

if (canContain (item))
{
item.setFile (file);
addChild (item, insertIndex);
}
}

bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
{
Item item (getProject(), ValueTree (Tags::file));
Expand Down Expand Up @@ -858,6 +861,14 @@ void Project::removeModule (const String& moduleID)
modules.removeChild (i, getUndoManagerFor (modules));
}


void Project::createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const
{
for (int i = 0; i < availableModules.modules.size(); ++i)
if (isModuleEnabled (availableModules.modules.getUnchecked(i)->uid))
modules.add (availableModules.modules.getUnchecked(i)->create());
}

//==============================================================================
ValueTree Project::getConfigurations() const
{
Expand Down
5 changes: 5 additions & 0 deletions extras/Introjucer/Source/Project/jucer_Project.h
Expand Up @@ -29,6 +29,8 @@
#include "../jucer_Headers.h"
class ProjectExporter;
class ProjectType;
class ModuleList;
class LibraryModule;

//==============================================================================
class Project : public FileBasedDocument,
Expand Down Expand Up @@ -162,6 +164,7 @@ class Project : public FileBasedDocument,
Item getOrCreateSubGroup (const String& name);
void addChild (const Item& newChild, int insertIndex);
bool addFile (const File& file, int insertIndex, bool shouldCompile);
void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
void removeItemFromProject();
void sortAlphabetically (bool keepGroupsAtStart);
Expand Down Expand Up @@ -271,6 +274,8 @@ class Project : public FileBasedDocument,
void addModule (const String& moduleID);
void removeModule (const String& moduleID);

void createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const;

//==============================================================================
String getFileTemplate (const String& templateName);

Expand Down
2 changes: 1 addition & 1 deletion extras/Introjucer/Source/Project/jucer_ProjectExporter.cpp
Expand Up @@ -210,7 +210,7 @@ void ProjectExporter::createPropertyEditors (Array <PropertyComponent*>& props)
props.getLast()->setTooltip ("The location of the Juce library folder that the " + name + " project will use to when compiling. This can be an absolute path, or relative to the jucer project folder, but it must be valid on the filesystem of the machine you use to actually do the compiling.");

OwnedArray<LibraryModule> modules;
project.getProjectType().createRequiredModules (project, ModuleList::getInstance(), modules);
project.createRequiredModules (ModuleList::getInstance(), modules);
for (int i = 0; i < modules.size(); ++i)
modules.getUnchecked(i)->createPropertyEditors (*this, props);

Expand Down
Expand Up @@ -18,6 +18,7 @@

//[CppHeaders] You can add your own extra header files here...
#include "jucer_ProjectExporter.h"
#include "jucer_Module.h"
//[/CppHeaders]

#include "jucer_ProjectInformationComponent.h"
Expand Down
8 changes: 4 additions & 4 deletions extras/Introjucer/Source/Project/jucer_ProjectSaver.h
Expand Up @@ -27,6 +27,7 @@
#define __JUCER_PROJECTSAVER_JUCEHEADER__

#include "jucer_ResourceFile.h"
#include "jucer_Module.h"


//==============================================================================
Expand Down Expand Up @@ -214,7 +215,7 @@ class ProjectSaver
<< "*/" << newLine << newLine;

OwnedArray<LibraryModule> modules;
project.getProjectType().createRequiredModules (project, ModuleList::getInstance(), modules);
project.createRequiredModules (ModuleList::getInstance(), modules);
bool anyFlags = false;

for (int j = 0; j < modules.size(); ++j)
Expand Down Expand Up @@ -291,7 +292,7 @@ class ProjectSaver

{
OwnedArray<LibraryModule> modules;
project.getProjectType().createRequiredModules (project, ModuleList::getInstance(), modules);
project.createRequiredModules (ModuleList::getInstance(), modules);

for (int i = 0; i < modules.size(); ++i)
modules.getUnchecked(i)->writeIncludes (project, out);
Expand Down Expand Up @@ -384,7 +385,7 @@ class ProjectSaver
const ValueTree originalGeneratedGroup (generatedFilesGroup.getNode().createCopy());

OwnedArray<LibraryModule> modules;
project.getProjectType().createRequiredModules (project, ModuleList::getInstance(), modules);
project.createRequiredModules (ModuleList::getInstance(), modules);

for (int i = project.getNumExporters(); --i >= 0;)
{
Expand All @@ -400,7 +401,6 @@ class ProjectSaver
modules.getUnchecked(j)->prepareExporter (*exporter, *this);

sortGroupRecursively (generatedFilesGroup);

exporter->groups.add (generatedFilesGroup);

try
Expand Down
7 changes: 0 additions & 7 deletions extras/Introjucer/Source/Project/jucer_ProjectType.cpp
Expand Up @@ -59,13 +59,6 @@ const ProjectType* ProjectType::findType (const String& typeCode)
return nullptr;
}

void ProjectType::createRequiredModules (Project& project, const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const
{
for (int i = 0; i < availableModules.modules.size(); ++i)
if (project.isModuleEnabled (availableModules.modules.getUnchecked(i)->uid))
modules.add (availableModules.modules.getUnchecked(i)->create());
}

//==============================================================================
class ProjectType_GUIApp : public ProjectType
{
Expand Down
6 changes: 2 additions & 4 deletions extras/Introjucer/Source/Project/jucer_ProjectType.h
Expand Up @@ -27,8 +27,8 @@
#define __JUCER_PROJECTTYPE_JUCEHEADER__

#include "../jucer_Headers.h"
#include "jucer_Module.h"

class Project;
class ProjectExporter;

//==============================================================================
class ProjectType
Expand Down Expand Up @@ -58,8 +58,6 @@ class ProjectType
virtual void setMissingProjectProperties (Project&) const = 0;
virtual void createPropertyEditors (const Project&, Array <PropertyComponent*>&) const = 0;
virtual void prepareExporter (ProjectExporter&) const = 0;
virtual void createRequiredModules (Project&, const ModuleList& availableModules,
OwnedArray<LibraryModule>& modules) const;

protected:
ProjectType (const String& type, const String& desc);
Expand Down
33 changes: 19 additions & 14 deletions extras/Introjucer/Source/Utility/jucer_FileHelpers.cpp
Expand Up @@ -30,6 +30,16 @@
//==============================================================================
namespace FileHelpers
{
int64 calculateMemoryHashCode (const void* data, const int numBytes)
{
int64 t = 0;

for (int i = 0; i < numBytes; ++i)
t = t * 65599 + static_cast <const uint8*> (data)[i];

return t;
}

int64 calculateStreamHashCode (InputStream& in)
{
int64 t = 0;
Expand Down Expand Up @@ -60,18 +70,14 @@ namespace FileHelpers

bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, int numBytes)
{
if (file.getSize() == numBytes)
{
MemoryInputStream newStream (data, numBytes, false);

if (calculateStreamHashCode (newStream) == calculateFileHashCode (file))
return true;
}

TemporaryFile temp (file);

return temp.getFile().appendData (data, numBytes)
&& temp.overwriteTargetFileWithTemporary();
if (file.getSize() == numBytes
&& calculateMemoryHashCode (data, numBytes) == calculateFileHashCode (file))
return true;

if (file.exists())
return file.replaceWithData (data, numBytes);
else
return file.appendData (data, numBytes);
}

bool overwriteFileWithNewDataIfDifferent (const File& file, const MemoryOutputStream& newData)
Expand Down Expand Up @@ -144,8 +150,7 @@ namespace FileHelpers
bool isJuceFolder (const File& folder)
{
return folder.getFileName().containsIgnoreCase ("juce")
&& folder.getChildFile ("juce.h").exists()
&& folder.getChildFile ("modules").exists();
&& folder.getChildFile ("modules").isDirectory();
}

static File lookInFolderForJuceFolder (const File& folder)
Expand Down
8 changes: 3 additions & 5 deletions modules/juce_core/files/juce_File.cpp
Expand Up @@ -689,12 +689,10 @@ bool File::appendData (const void* const dataToAppend,
{
if (numberOfBytes > 0)
{
const ScopedPointer <FileOutputStream> out (createOutputStream());
FileOutputStream out (*this, 8192);

if (out == 0)
return false;

out->write (dataToAppend, numberOfBytes);
return (! out.failedToOpen())
&& out.write (dataToAppend, numberOfBytes);
}

return true;
Expand Down

0 comments on commit d3bcbee

Please sign in to comment.