[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9667: Drop some unnecessary utility
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9667: Drop some unnecessary utility code. |
Date: |
Wed, 03 Sep 2008 17:58:23 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9667
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2008-09-03 17:58:23 +0200
message:
Drop some unnecessary utility code.
Other maintenance (renaming, cleanups).
modified:
libbase/utility.h
libcore/as_value.cpp
libcore/as_value.h
libcore/asobj/String_as.cpp
libcore/edit_text_character.cpp
libcore/parser/action_buffer.cpp
libcore/sprite_instance.cpp
libcore/sprite_instance.h
libcore/vm/ASHandlers.cpp
------------------------------------------------------------
revno: 9664.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 15:43:22 +0200
message:
Rename string_as_object to String_as.
modified:
libcore/asobj/String_as.cpp
------------------------------------------------------------
revno: 9664.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 15:43:49 +0200
message:
Fix warnings.
modified:
libcore/vm/ASHandlers.cpp
------------------------------------------------------------
revno: 9664.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 15:43:57 +0200
message:
Drop (private) get_type()
modified:
libcore/as_value.cpp
libcore/as_value.h
------------------------------------------------------------
revno: 9664.1.4
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 17:21:15 +0200
message:
Rearrange if into clearer switch.
Take int for a function where only ints are passed (although it's
not documented why an int is better than a double). Drop
infinite_to_fzero.
modified:
libcore/sprite_instance.cpp
libcore/sprite_instance.h
------------------------------------------------------------
revno: 9664.1.5
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 17:22:47 +0200
message:
Use boost's static assert instead of compiler_assert from utility.h
modified:
libcore/parser/action_buffer.cpp
------------------------------------------------------------
revno: 9664.1.6
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 17:23:20 +0200
message:
Use infinite_to_zero as this is a double, not a float.
modified:
libcore/edit_text_character.cpp
------------------------------------------------------------
revno: 9664.1.7
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-09-03 17:24:27 +0200
message:
Drop bernstein_hash, compiler_assert, infinite_to_fzero, ARRAYSIZE.
modified:
libbase/utility.h
=== modified file 'libbase/utility.h'
--- a/libbase/utility.h 2008-09-02 15:50:01 +0000
+++ b/libbase/utility.h 2008-09-03 15:24:27 +0000
@@ -16,8 +16,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
#ifndef UTILITY_H
#define UTILITY_H
@@ -27,7 +25,6 @@
#endif
#include <cassert>
-#include <cctype>
#include <string>
#include <typeinfo>
#include <cmath>
@@ -44,19 +41,14 @@
// On windows, replace ANSI assert with our own, for a less annoying
// debugging experience.
-//int tu_testbed_assert_break(const char* filename, int linenum, const char*
expression);
#ifndef __MINGW32__
#undef assert
-#define assert(x) if (!(x)) { __asm { int 3 } } //
tu_testbed_assert_break(__FILE__, __LINE__, #x))
+#define assert(x) if (!(x)) { __asm { int 3 } }
#endif
#endif // not NDEBUG
#endif // _WIN32
-// Compile-time assert. Thanks to Jon Jagger
-// (http://www.jaggersoft.com) for this trick.
-#define compiler_assert(x) switch(0){case 0: case x:;}
-
// Define this to enable fast float&double to uint32 conversion.
// If the behaviour is undefined when overflow occurs with your
// compiler, disable this macro.
@@ -88,12 +80,6 @@
#endif
}
-// TODO: deprecate this.
-inline float infinite_to_fzero(float x)
-{
- return utility::isFinite(x) ? x : 0.0f;
-}
-
inline double infinite_to_zero(double x)
{
return utility::isFinite(x) ? x : 0.0;
@@ -107,7 +93,7 @@
inline float flerp(float a, float b, float f)
{
- return static_cast<float>((b - a) * f + a);
+ return (b - a) * f + a;
}
inline int frnd(float f)
@@ -170,9 +156,9 @@
inline unsigned int
smallestMultipleContaining(unsigned int base, unsigned int x)
{
- int f=x/base;
- if ( x%base ) f++;
- return base*f;
+ int f = x / base;
+ if (x % base) f++;
+ return base*f;
}
@@ -190,7 +176,7 @@
if (status == 0)
{
typeName = typeNameUnmangled;
- free(typeNameUnmangled);
+ std::free(typeNameUnmangled);
}
#endif // __GNUC__ > 2
return typeName;
@@ -237,30 +223,6 @@
// Handy macro to quiet compiler warnings about unused parameters/variables.
#define UNUSED(x) (x) = (x)
-// Compile-time constant size of array.
-#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
-
-
-inline size_t bernstein_hash(const void* data_in, int size, unsigned int seed
= 5381)
-// Computes a hash of the given data buffer.
-// Hash function suggested by http://www.cs.yorku.ca/~oz/hash.html
-// Due to Dan Bernstein. Allegedly very good on strings.
-//
-// One problem with this hash function is that e.g. if you take a
-// bunch of 32-bit ints and hash them, their hash values will be
-// concentrated toward zero, instead of randomly distributed in
-// [0,2^32-1], because of shifting up only 5 bits per byte.
-{
- const unsigned char* data = static_cast<const unsigned char*>(data_in);
- unsigned int h = seed;
- while (size > 0) {
- size--;
- h = ((h << 5) + h) ^ static_cast<unsigned>(data[size]);
- }
-
- return h;
-}
-
#endif // UTILITY_H
=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp 2008-09-02 23:43:00 +0000
+++ b/libcore/as_value.cpp 2008-09-03 13:43:57 +0000
@@ -939,7 +939,7 @@
int SWFVersion = VM::get().getSWFVersion();
bool this_nulltype = (m_type == UNDEFINED || m_type == NULLTYPE);
- bool v_nulltype = (v.get_type() == UNDEFINED || v.get_type() == NULLTYPE);
+ bool v_nulltype = (v.m_type == UNDEFINED || v.m_type == NULLTYPE);
// It seems like functions are considered the same as a NULL type
// in SWF5 (and I hope below, didn't check)
@@ -1130,7 +1130,7 @@
const char*
as_value::typeOf() const
{
- switch(get_type())
+ switch(m_type)
{
case as_value::UNDEFINED:
return "undefined";
=== modified file 'libcore/as_value.h'
--- a/libcore/as_value.h 2008-09-02 22:57:53 +0000
+++ b/libcore/as_value.h 2008-09-03 13:43:57 +0000
@@ -603,13 +603,6 @@
///
bool equalsSameType(const as_value& v) const;
- // TODO: make private. The rationale is that callers of this functions
- // should use is_WHAT() instead, or changes in the available
- // primitive value types will require modifications in all
callers.
- // This happened when adding MOVIECLIP.
- //
- type get_type() const { return m_type; }
-
type m_type;
typedef sprite_instance* SpritePtr;
=== modified file 'libcore/asobj/String_as.cpp'
--- a/libcore/asobj/String_as.cpp 2008-09-01 18:11:06 +0000
+++ b/libcore/asobj/String_as.cpp 2008-09-03 13:43:22 +0000
@@ -155,11 +155,11 @@
return o.get();
}
-class string_as_object : public as_object
+class String_as : public as_object
{
public:
- string_as_object(const std::string& s)
+ String_as(const std::string& s)
:
as_object(getStringInterface()),
_string(s)
@@ -196,7 +196,7 @@
static as_value
string_concat(const fn_call& fn)
{
- boost::intrusive_ptr<string_as_object> obj =
ensureType<string_as_object>(fn.this_ptr);
+ boost::intrusive_ptr<String_as> obj = ensureType<String_as>(fn.this_ptr);
// Make a copy of our string.
std::string str = obj->str();
@@ -740,8 +740,8 @@
static as_value
string_to_string(const fn_call& fn)
{
- boost::intrusive_ptr<string_as_object> obj
- = ensureType<string_as_object>(fn.this_ptr);
+ boost::intrusive_ptr<String_as> obj
+ = ensureType<String_as>(fn.this_ptr);
return as_value(obj->str());
}
@@ -761,7 +761,7 @@
return as_value(str);
}
- boost::intrusive_ptr<string_as_object> obj = new string_as_object(str);
+ boost::intrusive_ptr<String_as> obj = new String_as(str);
return as_value(obj.get());
}
=== modified file 'libcore/edit_text_character.cpp'
--- a/libcore/edit_text_character.cpp 2008-08-29 09:12:54 +0000
+++ b/libcore/edit_text_character.cpp 2008-09-03 15:23:20 +0000
@@ -907,7 +907,7 @@
case NSV::PROP_uX:
{
matrix m = get_matrix();
- double x = utility::infinite_to_fzero( val.to_number() );
+ double x = utility::infinite_to_zero( val.to_number() );
m.tx = PIXELS_TO_TWIPS(x);
set_matrix(m); // no need to update caches when only changing
translation
@@ -917,7 +917,7 @@
case NSV::PROP_uY:
{
matrix m = get_matrix();
- double y = utility::infinite_to_fzero( val.to_number() );
+ double y = utility::infinite_to_zero( val.to_number() );
m.ty = PIXELS_TO_TWIPS(y);
set_matrix(m); // no need to update caches when only changing
translation
=== modified file 'libcore/parser/action_buffer.cpp'
--- a/libcore/parser/action_buffer.cpp 2008-08-18 23:53:04 +0000
+++ b/libcore/parser/action_buffer.cpp 2008-09-03 15:22:47 +0000
@@ -33,6 +33,7 @@
#include <typeinfo>
#include <string>
+#include <boost/static_assert.hpp>
using std::string;
using std::endl;
@@ -611,7 +612,7 @@
} c;
} u;
- compiler_assert(sizeof(u) == sizeof(u.i));
+ BOOST_STATIC_ASSERT(sizeof(u) == sizeof(u.i));
// Detect endianness of doubles by storing a value that is
// exactly representable and that has different values in the
=== modified file 'libcore/sprite_instance.cpp'
--- a/libcore/sprite_instance.cpp 2008-09-01 18:11:06 +0000
+++ b/libcore/sprite_instance.cpp 2008-09-03 15:21:15 +0000
@@ -1392,151 +1392,139 @@
{
boost::intrusive_ptr<sprite_instance> sprite =
ensureType<sprite_instance>(fn.this_ptr);
- boost::uint16_t thickness = 0;
- boost::uint8_t r = 0;
- boost::uint8_t g = 0;
- boost::uint8_t b = 0;
- boost::uint8_t a = 255;
-
-
- if ( ! fn.nargs )
- {
- sprite->resetLineStyle();
- return as_value();
- }
-
- thickness =
boost::uint16_t(PIXELS_TO_TWIPS(boost::uint16_t(utility::clamp<float>(fn.arg(0).to_number(),
0, 255))));
- bool scaleThicknessVertically = true;
- bool scaleThicknessHorizontally = true;
- bool pixelHinting = false;
- bool noClose = false;
- cap_style_e capStyle = CAP_ROUND;
- join_style_e joinStyle = JOIN_ROUND;
- float miterLimitFactor = 1.0f;
-
- if ( fn.nargs > 1 )
- {
- // 2^24 is the max here
- boost::uint32_t rgbval =
boost::uint32_t(utility::clamp<float>(fn.arg(1).to_number(), 0, 16777216));
- r = boost::uint8_t( (rgbval&0xFF0000) >> 16);
- g = boost::uint8_t( (rgbval&0x00FF00) >> 8);
- b = boost::uint8_t( (rgbval&0x0000FF) );
-
- if ( fn.nargs > 2 )
- {
- float alphaval = utility::clamp<float>(fn.arg(2).to_number(), 0, 100);
- a = boost::uint8_t( 255 * (alphaval/100) );
-
- if ( fn.nargs > 3 )
- {
- int swfVersion = sprite->getVM().getSWFVersion();
- if ( swfVersion < 8 )
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror(_("MovieClip.lineStyle(%s): args after the first three
will be discarded"), ss.str());
- );
- }
- else
- {
- pixelHinting = fn.arg(3).to_bool();
- if ( fn.nargs > 4 )
- {
- std::string noScaleString = fn.arg(4).to_string();
- if ( noScaleString == "none" )
- {
- scaleThicknessVertically = scaleThicknessHorizontally = false;
- }
- else if ( noScaleString == "vertical" )
- {
- scaleThicknessVertically = false;
- scaleThicknessHorizontally = true;
- }
- else if ( noScaleString == "horizontal" )
- {
- scaleThicknessVertically = true;
- scaleThicknessHorizontally = false;
- }
- else if ( noScaleString == "normal" )
- {
- scaleThicknessVertically = true;
- scaleThicknessHorizontally = true;
- }
- else
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror(_("MovieClip.lineStyle(%s): invalid noScale value
'%s' (valid values: %s|%s|%s|%s)"),
- ss.str(), noScaleString, "none", "vertical", "horizontal",
"normal");
- );
- }
- }
- if ( fn.nargs > 5 )
- {
- std::string capStyleStr = fn.arg(5).to_string();
- if ( capStyleStr == "none" )
- {
- capStyle = CAP_NONE;
- }
- else if ( capStyleStr == "round" )
- {
- capStyle = CAP_ROUND;
- }
- else if ( capStyleStr == "square" )
- {
- capStyle = CAP_SQUARE;
- }
- else
- {
- IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror(_("MovieClip.lineStyle(%s): invalid capStyle value
'%s' (valid values: %s|%s|%s)"), ss.str(),
- capStyleStr, "none", "round", "square");
- );
- }
- }
- if ( fn.nargs > 6 )
- {
+ if ( ! fn.nargs )
+ {
+ sprite->resetLineStyle();
+ return as_value();
+ }
+
+ boost::uint8_t r = 0;
+ boost::uint8_t g = 0;
+ boost::uint8_t b = 0;
+ boost::uint8_t a = 255;
+ boost::uint16_t thickness = 0;
+ bool scaleThicknessVertically = true;
+ bool scaleThicknessHorizontally = true;
+ bool pixelHinting = false;
+ bool noClose = false;
+ cap_style_e capStyle = CAP_ROUND;
+ join_style_e joinStyle = JOIN_ROUND;
+ float miterLimitFactor = 1.0f;
+
+ int arguments = fn.nargs;
+
+ const int swfVersion = sprite->getVM().getSWFVersion();
+ if (swfVersion < 8 && fn.nargs > 3)
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::ostringstream ss;
+ fn.dump_args(ss);
+ log_aserror(_("MovieClip.lineStyle(%s): args after the "
+ "first three will be discarded"), ss.str());
+ );
+ arguments = 3;
+ }
+
+ switch (arguments)
+ {
+ default:
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::ostringstream ss;
+ fn.dump_args(ss);
+ log_aserror(_("MovieClip.lineStyle(%s): args after the "
+ "first eight will be discarded"), ss.str());
+ );
+ case 8:
+ miterLimitFactor = utility::clamp<int>(fn.arg(7).to_int(), 1, 255);
+ case 7:
+ {
std::string joinStyleStr = fn.arg(6).to_string();
- if ( joinStyleStr == "miter" )
- {
- joinStyle = JOIN_MITER;
- }
- else if ( joinStyleStr == "round" )
- {
- joinStyle = JOIN_ROUND;
- }
- else if ( joinStyleStr == "bevel" )
- {
- joinStyle = JOIN_BEVEL;
- }
+ if (joinStyleStr == "miter") joinStyle = JOIN_MITER;
+ else if (joinStyleStr == "round") joinStyle = JOIN_ROUND;
+ else if (joinStyleStr == "bevel") joinStyle = JOIN_BEVEL;
else
{
IF_VERBOSE_ASCODING_ERRORS(
- std::stringstream ss; fn.dump_args(ss);
- log_aserror(_("MovieClip.lineStyle(%s): invalid jointStyle value
'%s' (valid values: %s|%s|%s)"), ss.str(),
- joinStyleStr, "miter", "round", "bevel");
+ std::ostringstream ss;
+ fn.dump_args(ss);
+ log_aserror(_("MovieClip.lineStyle(%s): invalid joinStyle"
+ "value '%s' (valid values: %s|%s|%s)"),
ss.str(),
+ joinStyleStr, "miter", "round", "bevel");
);
}
- }
- if ( fn.nargs > 7 )
- {
- miterLimitFactor = utility::clamp<int>(fn.arg(7).to_int(), 1, 255);
- }
-
- IF_VERBOSE_ASCODING_ERRORS(
- if ( fn.nargs > 8 )
- {
- std::stringstream ss; fn.dump_args(ss);
- log_aserror(_("MovieClip.lineStyle(%s): args after the first eight
will be discarded"), ss.str());
- }
- )
-
- }
- }
+ }
+ case 6:
+ {
+
+ const std::string capStyleStr = fn.arg(5).to_string();
+
+ if (capStyleStr == "none") capStyle = CAP_NONE;
+ else if (capStyleStr == "round") capStyle = CAP_ROUND;
+ else if (capStyleStr == "square") capStyle = CAP_SQUARE;
+ else
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::ostringstream ss;
+ fn.dump_args(ss);
+ log_aserror(_("MovieClip.lineStyle(%s): invalid capStyle "
+ "value '%s' (valid values: none|round|square)"),
+ ss.str(), capStyleStr);
+ );
+ }
+ }
+ case 5:
+ {
+ // Both values to be set here are true, so just set the
+ // appropriate values to false.
+ const std::string noScaleString = fn.arg(4).to_string();
+ if (noScaleString == "none")
+ {
+ scaleThicknessVertically = false;
+ scaleThicknessHorizontally = false;
+ }
+ else if (noScaleString == "vertical")
+ {
+ scaleThicknessVertically = false;
+ }
+ else if (noScaleString == "horizontal")
+ {
+ scaleThicknessHorizontally = false;
+ }
+ else if (noScaleString != "normal")
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::ostringstream ss;
+ fn.dump_args(ss);
+ log_aserror(_("MovieClip.lineStyle(%s): invalid "
+ "noScale value '%s' (valid values: "
+ "%s|%s|%s|%s)"),
+ ss.str(), noScaleString, "none",
+ "vertical", "horizontal", "normal");
+ );
+ }
+ }
+ case 4:
+ pixelHinting = fn.arg(3).to_bool();
+ case 3:
+ {
+ const float alphaval =
utility::clamp<float>(fn.arg(2).to_number(), 0, 100);
+ a = boost::uint8_t(255 * (alphaval / 100));
+ }
+ case 2:
+ {
+ boost::uint32_t rgbval =
boost::uint32_t(utility::clamp<float>(fn.arg(1).to_number(), 0, 16777216));
+ r = boost::uint8_t((rgbval & 0xFF0000) >> 16);
+ g = boost::uint8_t((rgbval & 0x00FF00) >> 8);
+ b = boost::uint8_t((rgbval & 0x0000FF) );
+ }
+ case 1:
+ thickness = boost::uint16_t(
+ PIXELS_TO_TWIPS(
+ boost::uint16_t(
+ utility::clamp<float>(fn.arg(0).to_number(), 0, 255)
+ )));
+ break;
}
- }
-
rgba color(r, g, b, a);
//log_debug("Color: %s", color.toString());
@@ -2744,7 +2732,7 @@
}
boost::intrusive_ptr<character>
-sprite_instance::add_textfield(const std::string& name, int depth, float x,
float y, float width, float height)
+sprite_instance::add_textfield(const std::string& name, int depth, int x, int
y, float width, float height)
{
// Create a definition (TODO: cleanup this thing, definitions should be
immutable!)
boost::intrusive_ptr<edit_text_character_def> txt = new
edit_text_character_def();
@@ -2765,8 +2753,6 @@
txt_char->setDynamic();
// Set _x and _y
- x = utility::infinite_to_fzero(x);
- y = utility::infinite_to_fzero(y);
matrix txt_matrix;
txt_matrix.set_translation(PIXELS_TO_TWIPS(x), PIXELS_TO_TWIPS(y));
txt_char->set_matrix(txt_matrix, true); // update caches (altought shouldn't
be needed as we only set translation)
@@ -4119,7 +4105,9 @@
event_id(event_id::DRAG_OUT),
};
- for (unsigned int i = 0; i < ARRAYSIZE(EH); i++)
+ static const size_t size = sizeof(EH) / sizeof(EH[0]);
+
+ for (size_t i = 0; i < size; i++)
{
const event_id &event = EH[i];
=== modified file 'libcore/sprite_instance.h'
--- a/libcore/sprite_instance.h 2008-08-26 13:30:20 +0000
+++ b/libcore/sprite_instance.h 2008-09-03 15:21:15 +0000
@@ -344,7 +344,7 @@
character* add_empty_movieclip(const char* name, int depth);
boost::intrusive_ptr<character> add_textfield(const std::string& name,
- int depth, float x, float y, float width, float height);
+ int depth, int x, int y, float width, float height);
/// Place a character or mask to the DisplayList.
//
=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2008-09-01 11:06:38 +0000
+++ b/libcore/vm/ASHandlers.cpp 2008-09-03 13:43:49 +0000
@@ -56,7 +56,6 @@
#include <string>
#include <vector>
#include <locale>
-#include <cerrno>
#include <cstdlib> // std::mbstowcs
#include <boost/scoped_array.hpp>
#include <boost/random.hpp>
@@ -2796,7 +2795,7 @@
std::auto_ptr< std::vector<as_value> > args ( new std::vector<as_value> );
args->reserve(nargs);
- for (int i=0; i<nargs; ++i) args->push_back(env.pop());
+ for (size_t i=0; i<nargs; ++i) args->push_back(env.pop());
//log_debug("ActionCallFunction calling call_method with %p as this_ptr",
this_ptr);
as_value result = call_method(function, &env, this_ptr,
@@ -3452,7 +3451,7 @@
std::auto_ptr< std::vector<as_value> > args ( new std::vector<as_value> );
args->reserve(nargs);
- for (int i=0; i<nargs; ++i) args->push_back(env.pop());
+ for (size_t i=0; i<nargs; ++i) args->push_back(env.pop());
as_value result = call_method(method_val, &env, this_ptr,
args, super);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9667: Drop some unnecessary utility code.,
Benjamin Wolsey <=