[svn:parrot] r45508 - in branches/immutable_strings_part1: include/parrot src/string
bacek at svn.parrot.org
bacek at svn.parrot.org
Sat Apr 10 13:35:16 UTC 2010
Author: bacek
Date: Sat Apr 10 13:35:16 2010
New Revision: 45508
URL: https://trac.parrot.org/parrot/changeset/45508
Log:
Merge str_chopn_inplace with str_chopn
Modified:
branches/immutable_strings_part1/include/parrot/string_funcs.h
branches/immutable_strings_part1/src/string/api.c
Modified: branches/immutable_strings_part1/include/parrot/string_funcs.h
==============================================================================
--- branches/immutable_strings_part1/include/parrot/string_funcs.h Sat Apr 10 13:35:02 2010 (r45507)
+++ branches/immutable_strings_part1/include/parrot/string_funcs.h Sat Apr 10 13:35:16 2010 (r45508)
@@ -96,12 +96,6 @@
FUNC_MODIFIES(*s);
PARROT_EXPORT
-void Parrot_str_chopn_inplace(PARROT_INTERP, ARGMOD(STRING *s), INTVAL n)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*s);
-
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_str_compare(PARROT_INTERP,
ARGIN_NULLOK(const STRING *s1),
@@ -521,9 +515,6 @@
#define ASSERT_ARGS_Parrot_str_chopn __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(s))
-#define ASSERT_ARGS_Parrot_str_chopn_inplace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_str_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_compose __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Modified: branches/immutable_strings_part1/src/string/api.c
==============================================================================
--- branches/immutable_strings_part1/src/string/api.c Sat Apr 10 13:35:02 2010 (r45507)
+++ branches/immutable_strings_part1/src/string/api.c Sat Apr 10 13:35:16 2010 (r45508)
@@ -1248,68 +1248,47 @@
Parrot_str_chopn(PARROT_INTERP, ARGMOD(STRING *s), INTVAL n)
{
ASSERT_ARGS(Parrot_str_chopn)
- STRING * const chopped = Parrot_str_copy(interp, s);
- Parrot_str_chopn_inplace(interp, chopped, n);
- return chopped;
-}
-
-
-/*
-
-=item C<void Parrot_str_chopn_inplace(PARROT_INTERP, STRING *s, INTVAL n)>
-
-Removes the last C<n> characters of the specified Parrot string. If C<n> is
-negative, cuts the string after C<+n> characters. The string passed in is
-modified and returned.
-
-=cut
-*/
-
-PARROT_EXPORT
-void
-Parrot_str_chopn_inplace(PARROT_INTERP, ARGMOD(STRING *s), INTVAL n)
-{
- ASSERT_ARGS(Parrot_str_chopn_inplace)
UINTVAL new_length, uchar_size;
+ STRING * const chopped = Parrot_gc_new_string_header(interp, 0);
+ STRUCT_COPY(chopped, s);
if (n < 0) {
new_length = -n;
- if (new_length > s->strlen)
- return;
+ if (new_length > chopped->strlen)
+ return chopped;
}
else {
- if (s->strlen > (UINTVAL)n)
- new_length = s->strlen - n;
+ if (chopped->strlen > (UINTVAL)n)
+ new_length = chopped->strlen - n;
else
new_length = 0;
}
- s->hashval = 0;
+ chopped->hashval = 0;
- if (!new_length || !s->strlen) {
- s->bufused = s->strlen = 0;
- return;
+ if (!new_length || !chopped->strlen) {
+ chopped->bufused = chopped->strlen = 0;
+ return chopped;
}
- uchar_size = s->bufused / s->strlen;
- s->strlen = new_length;
+ uchar_size = chopped->bufused / chopped->strlen;
+ chopped->strlen = new_length;
- if (s->encoding == Parrot_fixed_8_encoding_ptr) {
- s->bufused = new_length;
+ if (chopped->encoding == Parrot_fixed_8_encoding_ptr) {
+ chopped->bufused = new_length;
}
- else if (s->encoding == Parrot_ucs2_encoding_ptr) {
- s->bufused = new_length * uchar_size;
+ else if (chopped->encoding == Parrot_ucs2_encoding_ptr) {
+ chopped->bufused = new_length * uchar_size;
}
else {
String_iter iter;
ENCODING_ITER_INIT(interp, s, &iter);
iter.set_position(interp, &iter, new_length);
- s->bufused = iter.bytepos;
+ chopped->bufused = iter.bytepos;
}
-
- return;
+ return chopped;
}
More information about the parrot-commits
mailing list