1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Made a few constant string arrays static to help compilers to optimise their initialisation.

This commit is contained in:
jules 2013-10-17 10:42:58 +01:00
parent 674c0704fe
commit 81435f8134
21 changed files with 170 additions and 171 deletions

View file

@ -55,13 +55,13 @@ public:
if (file.hasFileExtension (sourceFileExtensions))
{
const char* extensions[] = { "h", "hpp", "hxx", "hh", nullptr };
static const char* extensions[] = { "h", "hpp", "hxx", "hh", nullptr };
return findCounterpart (file, extensions);
}
if (file.hasFileExtension (headerFileExtensions))
{
const char* extensions[] = { "cpp", "mm", "cc", "cxx", "c", "m", nullptr };
static const char* extensions[] = { "cpp", "mm", "cc", "cxx", "c", "m", nullptr };
return findCounterpart (file, extensions);
}

View file

@ -277,7 +277,7 @@ private:
{
XmlElement* const linker = xml.createNewChildElement ("Linker");
const char* defaultLibs[] = { "gdi32", "user32", "kernel32", "comctl32" };
static const char* defaultLibs[] = { "gdi32", "user32", "kernel32", "comctl32" };
StringArray libs (defaultLibs, numElementsInArray (defaultLibs));
libs.addTokens (getExternalLibrariesString(), ";\n", "\"'");

View file

@ -180,14 +180,14 @@ protected:
"you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
"send them to the user's temp folder.");
const char* const warningLevelNames[] = { "Low", "Medium", "High", nullptr };
static const char* warningLevelNames[] = { "Low", "Medium", "High", nullptr };
const int warningLevels[] = { 2, 3, 4 };
props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
StringArray (warningLevelNames), Array<var> (warningLevels, numElementsInArray (warningLevels))));
{
const char* const runtimeNames[] = { "(Default)", "Use static runtime", "Use DLL runtime", nullptr };
static const char* runtimeNames[] = { "(Default)", "Use static runtime", "Use DLL runtime", nullptr };
const var runtimeValues[] = { var(), var (false), var (true) };
props.add (new ChoicePropertyComponent (getUsingRuntimeLibDLL(), "Runtime Library",
@ -195,7 +195,7 @@ protected:
}
{
const char* const wpoNames[] = { "Enable link-time code generation when possible",
static const char* wpoNames[] = { "Enable link-time code generation when possible",
"Always disable link-time code generation", nullptr };
const var wpoValues[] = { var(), var (1) };
@ -211,7 +211,7 @@ protected:
props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
{
const char* const characterSetNames[] = { "Default", "MultiByte", "Unicode", nullptr };
static const char* characterSetNames[] = { "Default", "MultiByte", "Unicode", nullptr };
const var charSets[] = { var::null, "MultiByte", "Unicode", };
props.add (new ChoicePropertyComponent (getCharacterSetValue(), "Character Set",
@ -1526,7 +1526,7 @@ public:
{
MSVCProjectExporterVC2010::createExporterProperties (props);
const char* const toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", nullptr };
static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", nullptr };
const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK" };
props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
@ -1578,7 +1578,7 @@ public:
{
MSVCProjectExporterVC2010::createExporterProperties (props);
const char* const toolsetNames[] = { "(default)", "v120", "v120_xp", nullptr };
static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", nullptr };
const var toolsets[] = { var(), "v120", "v120_xp" };
props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",

View file

@ -87,7 +87,7 @@ protected:
void createConfigProperties (PropertyListBuilder& props) override
{
const char* const archNames[] = { "(Default)", "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7" };
static const char* const archNames[] = { "(Default)", "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7" };
const var archFlags[] = { var(), "-m32", "-m64", "-march=armv6", "-march=armv7" };
props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",

View file

@ -595,7 +595,7 @@ void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBui
props.add (new BooleanPropertyComponent (isDebugValue(), "Debug mode", "Debugging enabled"),
"If enabled, this means that the configuration should be built with debug synbols.");
const char* optimisationLevels[] = { "No optimisation", "Minimise size", "Maximise speed", 0 };
static const char* optimisationLevels[] = { "No optimisation", "Minimise size", "Maximise speed", 0 };
const int optimisationLevelValues[] = { optimisationOff, optimiseMinSize, optimiseMaxSpeed, 0 };
props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation",
StringArray (optimisationLevels), Array<var> (optimisationLevelValues)),

View file

@ -255,7 +255,7 @@ private:
static bool shouldFileBeKept (const String& filename)
{
const char* filesToKeep[] = { ".svn", ".cvs", "CMakeLists.txt" };
static const char* filesToKeep[] = { ".svn", ".cvs", "CMakeLists.txt" };
for (int i = 0; i < numElementsInArray (filesToKeep); ++i)
if (filename == filesToKeep[i])

View file

@ -294,7 +294,7 @@ namespace RTASHelpers
exporter.extraSearchPaths.add (juceWrapperFolder.toWindowsStyle());
const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
"AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
"AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
"AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
@ -329,7 +329,7 @@ namespace RTASHelpers
exporter.extraSearchPaths.add ("$(DEVELOPER_DIR)/Headers/FlatCarbon");
exporter.extraSearchPaths.add ("$(SDKROOT)/Developer/Headers/FlatCarbon");
const char* p[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
static const char* p[] = { "AlturaPorts/TDMPlugIns/PlugInLibrary/Controls",
"AlturaPorts/TDMPlugIns/PlugInLibrary/CoreClasses",
"AlturaPorts/TDMPlugIns/PlugInLibrary/DSPClasses",
"AlturaPorts/TDMPlugIns/PlugInLibrary/EffectClasses",
@ -453,7 +453,9 @@ namespace AUHelpers
#define JUCE_AU_PUBLICUTILITY "${DEVELOPER_DIR}/Extras/CoreAudio/PublicUtility/"
#define JUCE_AU_PUBLIC "${DEVELOPER_DIR}/Extras/CoreAudio/AudioUnits/AUPublic/"
const char* appleAUFiles[] = { JUCE_AU_PUBLICUTILITY "CADebugMacros.h",
static const char* appleAUFiles[] =
{
JUCE_AU_PUBLICUTILITY "CADebugMacros.h",
JUCE_AU_PUBLICUTILITY "CAAUParameter.cpp",
JUCE_AU_PUBLICUTILITY "CAAUParameter.h",
JUCE_AU_PUBLICUTILITY "CAAudioChannelLayout.cpp",
@ -500,7 +502,9 @@ namespace AUHelpers
JUCE_AU_PUBLIC "Utility/AUBuffer.h",
JUCE_AU_PUBLIC "Utility/AUInputFormatConverter.h",
JUCE_AU_PUBLIC "Utility/AUSilentTimeout.h",
JUCE_AU_PUBLIC "Utility/AUTimestampGenerator.h", 0 };
JUCE_AU_PUBLIC "Utility/AUTimestampGenerator.h",
nullptr
};
for (const char** f = appleAUFiles; *f != nullptr; ++f)
{

View file

@ -127,7 +127,7 @@ struct NewProjectWizardClasses
virtual StringArray getDefaultModules()
{
const char* mods[] =
static const char* mods[] =
{
"juce_core",
"juce_events",

View file

@ -963,9 +963,9 @@ double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOf
return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0);
}
String MidiMessage::getGMInstrumentName (const int n)
const char* MidiMessage::getGMInstrumentName (const int n)
{
const char* names[] =
static const char* names[] =
{
"Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
"Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
@ -992,12 +992,12 @@ String MidiMessage::getGMInstrumentName (const int n)
"Applause", "Gunshot"
};
return isPositiveAndBelow (n, (int) 128) ? names[n] : (const char*) 0;
return isPositiveAndBelow (n, numElementsInArray (names)) ? names[n] : nullptr;
}
String MidiMessage::getGMInstrumentBankName (const int n)
const char* MidiMessage::getGMInstrumentBankName (const int n)
{
const char* names[] =
static const char* names[] =
{
"Piano", "Chromatic Percussion", "Organ", "Guitar",
"Bass", "Strings", "Ensemble", "Brass",
@ -1005,12 +1005,12 @@ String MidiMessage::getGMInstrumentBankName (const int n)
"Synth Effects", "Ethnic", "Percussive", "Sound Effects"
};
return isPositiveAndBelow (n, (int) 16) ? names[n] : (const char*) 0;
return isPositiveAndBelow (n, numElementsInArray (names)) ? names[n] : nullptr;
}
String MidiMessage::getRhythmInstrumentName (const int n)
const char* MidiMessage::getRhythmInstrumentName (const int n)
{
const char* names[] =
static const char* names[] =
{
"Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
"Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
@ -1023,12 +1023,12 @@ String MidiMessage::getRhythmInstrumentName (const int n)
"Mute Triangle", "Open Triangle"
};
return (n >= 35 && n <= 81) ? names [n - 35] : (const char*) nullptr;
return (n >= 35 && n <= 81) ? names [n - 35] : nullptr;
}
String MidiMessage::getControllerName (const int n)
const char* MidiMessage::getControllerName (const int n)
{
const char* names[] =
static const char* names[] =
{
"Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
@ -1054,5 +1054,5 @@ String MidiMessage::getControllerName (const int n)
"Poly Operation"
};
return isPositiveAndBelow (n, (int) 128) ? names[n] : (const char*) nullptr;
return isPositiveAndBelow (n, numElementsInArray (names)) ? names[n] : nullptr;
}

View file

@ -889,30 +889,27 @@ public:
*/
static double getMidiNoteInHertz (int noteNumber, const double frequencyOfA = 440.0) noexcept;
/** Returns the standard name of a GM instrument.
/** Returns the standard name of a GM instrument, or nullptr if unknown for this index.
@param midiInstrumentNumber the program number 0 to 127
@see getProgramChangeNumber
*/
static String getGMInstrumentName (int midiInstrumentNumber);
/** Returns the name of a bank of GM instruments.
static const char* getGMInstrumentName (int midiInstrumentNumber);
/** Returns the name of a bank of GM instruments, or nullptr if unknown for this bank number.
@param midiBankNumber the bank, 0 to 15
*/
static String getGMInstrumentBankName (int midiBankNumber);
/** Returns the standard name of a channel 10 percussion sound.
static const char* getGMInstrumentBankName (int midiBankNumber);
/** Returns the standard name of a channel 10 percussion sound, or nullptr if unknown for this note number.
@param midiNoteNumber the key number, 35 to 81
*/
static String getRhythmInstrumentName (int midiNoteNumber);
/** Returns the name of a controller type number.
static const char* getRhythmInstrumentName (int midiNoteNumber);
/** Returns the name of a controller type number, or nullptr if unknown for this controller number.
@see getControllerNumber
*/
static String getControllerName (int controllerNumber);
static const char* getControllerName (int controllerNumber);
private:
//==============================================================================

View file

@ -536,7 +536,7 @@ AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
StringArray FlacAudioFormat::getQualityOptions()
{
const char* options[] = { "0 (Fastest)", "1", "2", "3", "4", "5 (Default)","6", "7", "8 (Highest quality)", 0 };
static const char* options[] = { "0 (Fastest)", "1", "2", "3", "4", "5 (Default)","6", "7", "8 (Highest quality)", 0 };
return StringArray (options);
}

View file

@ -180,11 +180,9 @@ bool LAMEEncoderAudioFormat::isCompressed() { return true; }
StringArray LAMEEncoderAudioFormat::getQualityOptions()
{
const char* vbrOptions[] = { "VBR quality 0 (best)", "VBR quality 1", "VBR quality 2", "VBR quality 3",
"VBR quality 4 (normal)", "VBR quality 5", "VBR quality 6", "VBR quality 7", "VBR quality 8",
"VBR quality 9 (smallest)",
nullptr };
static const char* vbrOptions[] = { "VBR quality 0 (best)", "VBR quality 1", "VBR quality 2", "VBR quality 3",
"VBR quality 4 (normal)", "VBR quality 5", "VBR quality 6", "VBR quality 7",
"VBR quality 8", "VBR quality 9 (smallest)", nullptr };
StringArray opts (vbrOptions);
const int cbrRates[] = { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 };

View file

@ -479,7 +479,7 @@ AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
StringArray OggVorbisAudioFormat::getQualityOptions()
{
const char* options[] = { "64 kbps", "80 kbps", "96 kbps", "112 kbps", "128 kbps", "160 kbps",
static const char* options[] = { "64 kbps", "80 kbps", "96 kbps", "112 kbps", "128 kbps", "160 kbps",
"192 kbps", "224 kbps", "256 kbps", "320 kbps", "500 kbps", 0 };
return StringArray (options);
}

View file

@ -206,7 +206,7 @@ bool Process::openDocument (const String& fileName, const String& parameters)
|| ! isFileExecutable (fileName))
{
// create a command that tries to launch a bunch of likely browsers
const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
static const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
"google-chrome", "chromium-browser", "opera", "konqueror" };
StringArray cmdLines;

View file

@ -132,14 +132,14 @@ namespace FileHelpers
bool File::isOnCDRomDrive() const
{
const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", nullptr };
return FileHelpers::isFileOnDriveType (*this, cdTypes);
}
bool File::isOnHardDisk() const
{
const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", nullptr };
return ! (isOnCDRomDrive() || FileHelpers::isFileOnDriveType (*this, nonHDTypes));
}

View file

@ -292,7 +292,7 @@ URL URL::getChildURL (const String& subPath) const
//==============================================================================
bool URL::isProbablyAWebsiteURL (const String& possibleURL)
{
const char* validProtocols[] = { "http:", "ftp:", "https:" };
static const char* validProtocols[] = { "http:", "ftp:", "https:" };
for (int i = 0; i < numElementsInArray (validProtocols); ++i)
if (possibleURL.startsWithIgnoreCase (validProtocols[i]))

View file

@ -409,8 +409,8 @@ String Time::getWeekdayName (const bool threeLetterVersion) const
String Time::getMonthName (int monthNumber, const bool threeLetterVersion)
{
const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
static const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
static const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
monthNumber %= 12;
@ -420,8 +420,8 @@ String Time::getMonthName (int monthNumber, const bool threeLetterVersion)
String Time::getWeekdayName (int day, const bool threeLetterVersion)
{
const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
static const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
day %= 7;

View file

@ -235,7 +235,7 @@ private:
static bool isFaceSansSerif (const String& family)
{
const char* sansNames[] = { "Sans", "Verdana", "Arial", "Ubuntu" };
static const char* sansNames[] = { "Sans", "Verdana", "Arial", "Ubuntu" };
for (int i = 0; i < numElementsInArray (sansNames); ++i)
if (family.containsIgnoreCase (sansNames[i]))

View file

@ -137,7 +137,7 @@ private:
StringArray allFonts;
FTTypefaceList::getInstance()->getSansSerifNames (allFonts);
const char* targets[] = { "Verdana", "Bitstream Vera Sans", "Luxi Sans",
static const char* targets[] = { "Verdana", "Bitstream Vera Sans", "Luxi Sans",
"Liberation Sans", "DejaVu Sans", "Sans", nullptr };
return pickBestFont (allFonts, targets);
}
@ -147,7 +147,7 @@ private:
StringArray allFonts;
FTTypefaceList::getInstance()->getSerifNames (allFonts);
const char* targets[] = { "Bitstream Vera Serif", "Times", "Nimbus Roman",
static const char* targets[] = { "Bitstream Vera Serif", "Times", "Nimbus Roman",
"Liberation Serif", "DejaVu Serif", "Serif", nullptr };
return pickBestFont (allFonts, targets);
}
@ -157,7 +157,7 @@ private:
StringArray allFonts;
FTTypefaceList::getInstance()->getMonospacedNames (allFonts);
const char* targets[] = { "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Sans Mono",
static const char* targets[] = { "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Sans Mono",
"Liberation Mono", "Courier", "DejaVu Mono", "Mono", nullptr };
return pickBestFont (allFonts, targets);
}

View file

@ -97,7 +97,7 @@ static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
MemoryBlock temp;
movieStream->readIntoMemoryBlock (temp);
const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
static const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
{

View file

@ -419,7 +419,7 @@ bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle
// different types to get QT to try. (We should really be a bit smarter here by
// working out in advance which one the stream contains, rather than just trying
// each one)
const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
static const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
"\04.avi", "\04.m4a" };
for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)