[svn:parrot] r41164 - in trunk: include/parrot src/string
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Tue Sep 8 21:05:36 UTC 2009
Author: chromatic
Date: Tue Sep 8 21:05:36 2009
New Revision: 41164
URL: https://trac.parrot.org/parrot/changeset/41164
Log:
[string] Made string_rep_compatible() static within src/string/api.c; this
means an optimizing compiler can inline it. It's only called from other
functions in this file and it doesn't follow the Parrot_* external naming
policy. This produces a 3.295% performance improvement in the STRING-heavy
examples/benchmarks/vpm.pir.
Modified:
trunk/include/parrot/string_funcs.h
trunk/src/string/api.c
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h Tue Sep 8 21:05:32 2009 (r41163)
+++ trunk/include/parrot/string_funcs.h Tue Sep 8 21:05:36 2009 (r41164)
@@ -523,18 +523,6 @@
__attribute__nonnull__(1);
PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-const CHARSET * string_rep_compatible(SHIM_INTERP,
- ARGIN(const STRING *a),
- ARGIN(const STRING *b),
- ARGOUT(const ENCODING **e))
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*e);
-
-PARROT_EXPORT
PARROT_MALLOC
PARROT_CAN_RETURN_NULL
char * string_to_cstring_nullable(SHIM_INTERP,
@@ -725,10 +713,6 @@
#define ASSERT_ARGS_string_primary_encoding_for_representation \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_string_rep_compatible __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(a) \
- || PARROT_ASSERT_ARG(b) \
- || PARROT_ASSERT_ARG(e)
#define ASSERT_ARGS_string_to_cstring_nullable __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_str_from_int_base __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c Tue Sep 8 21:05:32 2009 (r41163)
+++ trunk/src/string/api.c Tue Sep 8 21:05:36 2009 (r41164)
@@ -48,9 +48,24 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*s);
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static const CHARSET * string_rep_compatible(SHIM_INTERP,
+ ARGIN(const STRING *a),
+ ARGIN(const STRING *b),
+ ARGOUT(const ENCODING **e))
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*e);
+
#define ASSERT_ARGS_make_writable __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(s)
+#define ASSERT_ARGS_string_rep_compatible __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(a) \
+ || PARROT_ASSERT_ARG(b) \
+ || PARROT_ASSERT_ARG(e)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -378,8 +393,8 @@
/*
-=item C<const CHARSET * string_rep_compatible(PARROT_INTERP, const STRING *a,
-const STRING *b, const ENCODING **e)>
+=item C<static const CHARSET * string_rep_compatible(PARROT_INTERP, const STRING
+*a, const STRING *b, const ENCODING **e)>
Find the "lowest" possible charset and encoding for the given string. E.g.
@@ -392,10 +407,9 @@
*/
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
-const CHARSET *
+static const CHARSET *
string_rep_compatible(SHIM_INTERP,
ARGIN(const STRING *a), ARGIN(const STRING *b), ARGOUT(const ENCODING **e))
{
@@ -406,8 +420,8 @@
}
/* a table could possibly simplify the logic */
- if (a->encoding == Parrot_utf8_encoding_ptr &&
- b->charset == Parrot_ascii_charset_ptr) {
+ if (a->encoding == Parrot_utf8_encoding_ptr
+ && b->charset == Parrot_ascii_charset_ptr) {
if (a->strlen == a->bufused) {
*e = Parrot_fixed_8_encoding_ptr;
return b->charset;
@@ -415,8 +429,9 @@
*e = a->encoding;
return a->charset;
}
- if (b->encoding == Parrot_utf8_encoding_ptr &&
- a->charset == Parrot_ascii_charset_ptr) {
+
+ if (b->encoding == Parrot_utf8_encoding_ptr
+ && a->charset == Parrot_ascii_charset_ptr) {
if (b->strlen == b->bufused) {
*e = Parrot_fixed_8_encoding_ptr;
return a->charset;
@@ -424,11 +439,15 @@
*e = b->encoding;
return b->charset;
}
+
if (a->encoding != b->encoding)
return NULL;
+
if (a->encoding != Parrot_fixed_8_encoding_ptr)
return NULL;
+
*e = Parrot_fixed_8_encoding_ptr;
+
if (a->charset == b->charset)
return a->charset;
if (b->charset == Parrot_ascii_charset_ptr)
@@ -439,9 +458,11 @@
return a->charset;
if (b->charset == Parrot_binary_charset_ptr)
return b->charset;
+
return NULL;
}
+
/*
=item C<STRING * Parrot_str_concat(PARROT_INTERP, STRING *a, STRING *b, UINTVAL
@@ -464,8 +485,8 @@
ARGIN_NULLOK(STRING *b), UINTVAL Uflags)
{
ASSERT_ARGS(Parrot_str_concat)
- if (a != NULL && a->strlen != 0) {
- if (b != NULL && b->strlen != 0) {
+ if (a && a->strlen) {
+ if (b && b->strlen) {
const ENCODING *enc;
const CHARSET *cs = string_rep_compatible(interp, a, b, &enc);
STRING *result;
@@ -536,6 +557,7 @@
return Parrot_str_concat(interp, a, b, 0);
cs = string_rep_compatible(interp, a, b, &enc);
+
if (cs) {
a->charset = cs;
a->encoding = enc;
More information about the parrot-commits
mailing list