[svn:parrot] r36065 - in trunk: include/parrot src src/ops src/pmc src/string
[email protected] Tue, 27 Jan 2009 13:05:26 -0800 (PST)
| Newsgroups | perl.cvs.parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: julianalbo
Date: Tue Jan 27 13:05:25 2009
New Revision: 36065
Modified:
trunk/include/parrot/string_funcs.h
trunk/src/ops/string.ops
trunk/src/pmc/scalar.pmc
trunk/src/spf_render.c
trunk/src/string/api.c
trunk/src/trace.c
Log:
Implement Parrot_str_repeat and replace usages of string_repeat, TT # 210
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h (original)
+++ trunk/include/parrot/string_funcs.h Tue Jan 27 13:05:25 2009
@@ -52,6 +52,14 @@
FUNC_MODIFIES(*d);
PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+STRING * Parrot_str_repeat(PARROT_INTERP,
+ ARGIN(const STRING *s),
+ UINTVAL num)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
PARROT_PURE_FUNCTION
PARROT_CANNOT_RETURN_NULL
const char * Parrot_string_cstring(SHIM_INTERP, ARGIN(const STRING *str))
@@ -558,6 +566,9 @@
#define ASSERT_ARGS_Parrot_reuse_COW_reference __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(s) \
|| PARROT_ASSERT_ARG(d)
+#define ASSERT_ARGS_Parrot_str_repeat __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(s)
#define ASSERT_ARGS_Parrot_string_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(str)
#define ASSERT_ARGS_Parrot_string_find_cclass __attribute__unused__ int _ASSERT_ARGS_CHECK = \
Modified: trunk/src/ops/string.ops
==============================================================================
--- trunk/src/ops/string.ops (original)
+++ trunk/src/ops/string.ops Tue Jan 27 13:05:25 2009
@@ -142,7 +142,7 @@
"Cannot repeat with negative arg");
goto ADDRESS(handler);
}
- $1 = string_repeat(interp, $2, (UINTVAL)$3, NULL);
+ $1 = Parrot_str_repeat(interp, $2, (UINTVAL)$3);
}
inline op repeat(invar PMC, invar PMC, in INT) :base_core {
Modified: trunk/src/pmc/scalar.pmc
==============================================================================
--- trunk/src/pmc/scalar.pmc (original)
+++ trunk/src/pmc/scalar.pmc Tue Jan 27 13:05:25 2009
@@ -1153,7 +1153,7 @@
dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_string_native(INTERP, dest,
- string_repeat(INTERP, s, n, NULL));
+ Parrot_str_repeat(INTERP, s, n));
return dest;
}
@@ -1164,7 +1164,7 @@
dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_string_native(INTERP, dest,
- string_repeat(INTERP, s, n, NULL));
+ Parrot_str_repeat(INTERP, s, n));
return dest;
}
@@ -1172,13 +1172,13 @@
VTABLE void i_repeat(PMC *value) {
STRING * const s = SELF.get_string();
const UINTVAL n = (UINTVAL)VTABLE_get_integer(INTERP, value);
- SELF.set_string_native(string_repeat(INTERP, s, n, NULL));
+ SELF.set_string_native(Parrot_str_repeat(INTERP, s, n));
}
VTABLE void i_repeat_int(INTVAL value) {
STRING * const s = SELF.get_string();
const UINTVAL n = value;
- SELF.set_string_native(string_repeat(INTERP, s, n, NULL));
+ SELF.set_string_native(Parrot_str_repeat(INTERP, s, n));
}
Modified: trunk/src/spf_render.c
==============================================================================
--- trunk/src/spf_render.c (original)
+++ trunk/src/spf_render.c Tue Jan 27 13:05:25 2009
@@ -191,7 +191,7 @@
((info->flags & FLAG_ZERO) && !(info->flags & FLAG_MINUS))
? CONST_STRING(interp, "0")
: CONST_STRING(interp, " ");
- STRING * const fill = string_repeat(interp, filler, info->width - len, NULL);
+ STRING * const fill = Parrot_str_repeat(interp, filler, info->width - len);
if (info->flags & FLAG_MINUS) { /* left-align */
str = string_concat(interp, str, fill, 0);
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c (original)
+++ trunk/src/string/api.c Tue Jan 27 13:05:25 2009
@@ -1122,6 +1122,43 @@
/*
+=item C<STRING * Parrot_str_repeat>
+
+Repeats the specified Parrot string I<num> times and returns the result.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+STRING *
+Parrot_str_repeat(PARROT_INTERP, ARGIN(const STRING *s), UINTVAL num)
+{
+ ASSERT_ARGS(string_repeat)
+ STRING * const dest = string_make_direct(interp, NULL,
+ s->bufused * num,
+ s->encoding, s->charset, 0);
+ if (num > 0) {
+ /* copy s into dest num times */
+ UINTVAL length = s->bufused;
+ UINTVAL i;
+ char * destpos = dest->strstart;
+ const char * const srcpos = s->strstart;
+ for (i = 0; i < num; i++) {
+ mem_sys_memcopy(destpos, srcpos, length);
+ destpos+= length;
+ }
+
+ dest->bufused = s->bufused * num;
+ dest->strlen = s->strlen * num;
+ }
+
+ return dest;
+}
+
+/*
+
=item C<STRING * string_substr>
Copies the substring of length C<length> from C<offset> from the specified
Modified: trunk/src/trace.c
==============================================================================
--- trunk/src/trace.c (original)
+++ trunk/src/trace.c Tue Jan 27 13:05:25 2009
@@ -388,9 +388,9 @@
if (!more)
goto done;
if (len < ARGS_COLUMN) {
- STRING * const fill = string_repeat(debugger,
+ STRING * const fill = Parrot_str_repeat(debugger,
const_string(debugger, " "),
- ARGS_COLUMN - len, NULL);
+ ARGS_COLUMN);
Parrot_io_putps(debugger, Parrot_io_STDERR(debugger), fill);
}
else {