From f291fb57d087de41385a22dfacd8b694d8b9abc7 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 2 Mar 2012 17:05:57 +0000 Subject: customshapes: re-work generation to create many small methods each custom shape now has a virtual constructor we can call to construct it, this shrinks the function size, and helps the optimiser much accelerating compile time. It may even help improve import time too. --- oox/inc/oox/drawingml/customshapeproperties.hxx | 8 +- oox/source/drawingml/customshapeproperties.cxx | 4 +- .../drawingml/customshapes/generatePresetsCXX.pl | 104 ++++++++++++--------- 3 files changed, 68 insertions(+), 48 deletions(-) (limited to 'oox') diff --git a/oox/inc/oox/drawingml/customshapeproperties.hxx b/oox/inc/oox/drawingml/customshapeproperties.hxx index 004d7713d354..a36a022ed5a2 100644 --- a/oox/inc/oox/drawingml/customshapeproperties.hxx +++ b/oox/inc/oox/drawingml/customshapeproperties.hxx @@ -112,6 +112,12 @@ struct Path2D Path2D() : w( 0 ), h( 0 ), fill( XML_norm ), stroke( sal_True ), extrusionOk( sal_True ) {}; }; + +class CustomShapeProvider { +public: + virtual PropertyMap getProperties() = 0; +}; + class CustomShapeProperties { public: @@ -160,7 +166,7 @@ private: sal_Bool mbMirroredY; sal_Int32 mnTextRotateAngle; - typedef boost::unordered_map< sal_Int32, PropertyMap > PresetsMap; + typedef boost::unordered_map< sal_Int32, CustomShapeProvider * > PresetsMap; static PresetsMap maPresetsMap; static void initializePresetsMap(); diff --git a/oox/source/drawingml/customshapeproperties.cxx b/oox/source/drawingml/customshapeproperties.cxx index e5bb6d88e446..1b0cac256939 100644 --- a/oox/source/drawingml/customshapeproperties.cxx +++ b/oox/source/drawingml/customshapeproperties.cxx @@ -147,7 +147,9 @@ void CustomShapeProperties::pushToPropSet( const ::oox::core::FilterBase& /* rFi { OSL_TRACE("found property map for preset: %s (%d)", USS(getShapePresetTypeName()), mnShapePresetType); - aPropertyMap = maPresetsMap[ mnShapePresetType ]; + CustomShapeProvider *pProvider = maPresetsMap[ mnShapePresetType ]; + if (pProvider) + aPropertyMap = pProvider->getProperties(); #ifdef DEBUG aPropertyMap.dumpCode(); #endif diff --git a/oox/source/drawingml/customshapes/generatePresetsCXX.pl b/oox/source/drawingml/customshapes/generatePresetsCXX.pl index 827537c3a1d5..f2150ce99fd6 100755 --- a/oox/source/drawingml/customshapes/generatePresetsCXX.pl +++ b/oox/source/drawingml/customshapes/generatePresetsCXX.pl @@ -1,9 +1,5 @@ #!/usr/bin/perl -generateSource (loadSourceCode ()); - -exit; - sub loadSourceCode() { open (IN, "customshapepresets" . $count . ".cxx"); + print OUT << "EOS" +// this file was generated by: $0 // please do not edit #include \"oox/drawingml/customshapeproperties.hxx\" @@ -76,71 +75,84 @@ using namespace ::com::sun::star::uno; namespace oox { namespace drawingml { -void CustomShapeProperties::initializePresetsMap" . $count . "() +namespace { -"; +EOS +; - open (OUT, ">customshapepresets" . $count . ".cxx"); - print OUT $head; } sub endSource { - my $endBrace = shift; - my $tail = " -} -} - -"; + my $count = shift; + my $classes = shift; + $endBrace > 0 && print OUT "}\n\n"; + + print OUT "} // anonymous namespace\n"; + print OUT "void CustomShapeProperties::initializePresetsMap" . $count . "()\n"; + print OUT "{\n"; + for my $class (@{$classes}) + { + print OUT " maPresetsMap [ StaticTokenMap::get().getTokenFromUnicode( OUString( RTL_CONSTASCII_USTRINGPARAM( \"", $class, "\" ) ) ) ] = new ShapeC".$class."();\n"; + } + print OUT "} - if ($endBrace > 0) { - print OUT "}\n\n"; - } +} } // oox // drawingml - print OUT $tail; - close (OUT); +"; } sub generateSource { - $sources = shift; - $count = 1; - $shCount = 0; - - startSource($count++); - - foreach $shape (keys %$sources) - { - print OUT " {\n"; - print OUT " PropertyMap aPropertyMap;\n\n"; - print OUT @{$sources->{$shape}}; - print OUT " aPropertyMap [ PROP_Type ] <<= CREATE_OUSTRING(\"ooxml-", $shape, "\");\n\n"; - print OUT " maPresetsMap [ StaticTokenMap::get().getTokenFromUnicode( OUString( RTL_CONSTASCII_USTRINGPARAM( \"", $shape, "\" ) ) ) ] = aPropertyMap;\n"; - print OUT " }\n"; + my $sources = shift; + my $count = 0; + my $shCount = 0; + + startSource (++$count); + + my @classes = (); + foreach $shape (keys %$sources) + { + push @classes, $shape; + print OUT "class ShapeC".$shape." : public CustomShapeProvider\n"; + print OUT "{\n"; + print OUT " virtual PropertyMap getProperties()\n"; + print OUT " {\n"; + print OUT " PropertyMap aPropertyMap;\n\n"; + print OUT @{$sources->{$shape}}; + print OUT " aPropertyMap [ PROP_Type ] <<= CREATE_OUSTRING(\"ooxml-", $shape, "\");\n\n"; + print OUT " return aPropertyMap;\n"; + print OUT " }\n"; + print OUT "};\n"; $shCount++; if ($shCount >= 35) { $shCount = 0; - endSource(1); - startSource($count++); + endSource ($count, \@classes); + close OUT; + startSource (++$count); + @classes = (); } - } + } - print OUT " -} + endSource ($count, \@classes); -void CustomShapeProperties::initializePresetsMap() -{\n"; + print OUT << "EOS" - for ($i=1; $i < $count; $i++) { +void ::oox::drawingml::CustomShapeProperties::initializePresetsMap() +{ +EOS + ; + + for ($i=1; $i <= $count; $i++) { print OUT "initializePresetsMap" . $i . "();\n"; - } + } print OUT "}\n"; - if ($shCount > 0) { - endSource(0); - } + close OUT; } + +generateSource (loadSourceCode ()); -- cgit