diff --git a/CHANGES.current b/CHANGES.current index afb5d564c..18f5df2e5 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,7 +2,8 @@ Version 1.3.32 (in progress) ============================ 09/17/2007: olly - [PHP] Use std::string::assign(PTR, LEN) rather than assigning + When wrapping C++ code, generate code which uses + std::string::assign(PTR, LEN) rather than assigning std::string(PTR, LEN). Using assign generates more efficient code (tested with GCC 4.1.2). diff --git a/Lib/allegrocl/std_string.i b/Lib/allegrocl/std_string.i index cc92bebe3..c70532f7a 100755 --- a/Lib/allegrocl/std_string.i +++ b/Lib/allegrocl/std_string.i @@ -97,13 +97,13 @@ namespace std { // automatically convert constant std::strings to cl:strings %typemap(ctype) string "char *"; - %typemap(in) string "$1 = string($input);"; + %typemap(in) string "$1.assign($input);"; %typemap(out) string "$result = (char *)(&$1)->c_str();"; %typemap(lisptype) string "cl:string"; %typemap(lout) string "(cl::setq ACL_ffresult $body)"; %typemap(ctype) wstring "wchar_t *"; - %typemap(in) wstring "$1 = string($input);"; + %typemap(in) wstring "$1.assign($input);"; %typemap(out) wstring "$result = (wchar_t *)(&$1)->c_str();"; %typemap(lisptype) wstring "cl:string"; %typemap(lout) wstring "(cl::setq ACL_ffresult (excl:native-to-string $body @@ -112,16 +112,16 @@ namespace std { /* Overloading check */ // %typemap(in) string { // if (caml_ptr_check($input)) -// $1 = std::string((char *)caml_ptr_val($input,0), -// caml_string_len($input)); +// $1.assign((char *)caml_ptr_val($input,0), +// caml_string_len($input)); // else // SWIG_exception(SWIG_TypeError, "string expected"); // } // %typemap(in) const string & (std::string temp) { // if (caml_ptr_check($input)) { -// temp = std::string((char *)caml_ptr_val($input,0), -// caml_string_len($input)); +// temp.assign((char *)caml_ptr_val($input,0), +// caml_string_len($input)); // $1 = &temp; // } else { // SWIG_exception(SWIG_TypeError, "string expected"); @@ -130,8 +130,8 @@ namespace std { // %typemap(in) string & (std::string temp) { // if (caml_ptr_check($input)) { -// temp = std::string((char *)caml_ptr_val($input,0), -// caml_string_len($input)); +// temp.assign((char *)caml_ptr_val($input,0), +// caml_string_len($input)); // $1 = &temp; // } else { // SWIG_exception(SWIG_TypeError, "string expected"); @@ -158,8 +158,8 @@ namespace std { // } // %typemap(directorout) string { -// $result = std::string((char *)caml_ptr_val($input,0), -// caml_string_len($input)); +// $result.assign((char *)caml_ptr_val($input,0), +// caml_string_len($input)); // } // %typemap(out) string { diff --git a/Lib/chicken/std_string.i b/Lib/chicken/std_string.i index 36dd82b90..2955d0e2f 100644 --- a/Lib/chicken/std_string.i +++ b/Lib/chicken/std_string.i @@ -35,14 +35,14 @@ namespace std { %typemap(in) string (char* tempptr) { if ($input == C_SCHEME_FALSE) { - $1 = std::string(); + $1.resize(0); } else { if (!C_swig_is_string ($input)) { swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not a string"); - } + } tempptr = SWIG_MakeString($input); - $1 = std::string(tempptr); + $1.assign(tempptr); if (tempptr) SWIG_free(tempptr); } } @@ -51,7 +51,7 @@ namespace std { char* tempptr) { if ($input == C_SCHEME_FALSE) { - temp = std::string(); + temp.resize(0); $1 = &temp; } else { if (!C_swig_is_string ($input)) { @@ -59,7 +59,7 @@ namespace std { "Argument #$argnum is not a string"); } tempptr = SWIG_MakeString($input); - temp = std::string(tempptr); + temp.assign(tempptr); if (tempptr) SWIG_free(tempptr); $1 = &temp; } @@ -79,7 +79,7 @@ namespace std { %typemap(varin) string { if ($input == C_SCHEME_FALSE) { - $1 = std::string(); + $1.resize(0); } else { char *tempptr; if (!C_swig_is_string ($input)) { @@ -87,7 +87,7 @@ namespace std { "Argument #$argnum is not a string"); } tempptr = SWIG_MakeString($input); - $1 = std::string(tempptr); + $1.assign(tempptr); if (tempptr) SWIG_free(tempptr); } } diff --git a/Lib/csharp/std_string.i b/Lib/csharp/std_string.i index 2258b2c92..d29692717 100644 --- a/Lib/csharp/std_string.i +++ b/Lib/csharp/std_string.i @@ -35,7 +35,7 @@ class string; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0); return $null; } - $1 = std::string($input); %} + $1.assign($input); %} %typemap(out) string %{ $result = SWIG_csharp_string_callback($1.c_str()); %} %typemap(directorout, canthrow=1) string @@ -43,7 +43,7 @@ class string; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0); return $null; } - $result = std::string($input); %} + $result.assign($input); %} %typemap(directorin) string %{ $input = SWIG_csharp_string_callback($1.c_str()); %} diff --git a/Lib/csharp/std_wstring.i b/Lib/csharp/std_wstring.i index f1706f563..7b4387f21 100755 --- a/Lib/csharp/std_wstring.i +++ b/Lib/csharp/std_wstring.i @@ -36,7 +36,7 @@ class wstring; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0); return $null; } - $1 = std::wstring($input); %} + $1.assign($input); %} %typemap(out) wstring %{ $result = SWIG_csharp_wstring_callback($1.c_str()); %} %typemap(directorout, canthrow=1) wstring @@ -44,7 +44,7 @@ class wstring; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0); return $null; } - $result = std::wstring($input); %} + $result.assign($input); %} %typemap(directorin) wstring %{ $input = SWIG_csharp_wstring_callback($1.c_str()); %} diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i index 0e341ed0c..f80a65ca5 100644 --- a/Lib/guile/std_string.i +++ b/Lib/guile/std_string.i @@ -32,7 +32,7 @@ namespace std { %typemap(in) string (char* tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); - $1 = std::string(tempptr); + $1.assign(tempptr); if (tempptr) SWIG_free(tempptr); } else { SWIG_exception(SWIG_TypeError, "string expected"); @@ -43,7 +43,7 @@ namespace std { char* tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); - temp = std::string(tempptr); + temp.assign(tempptr); if (tempptr) SWIG_free(tempptr); $1 = &temp; } else { @@ -76,7 +76,7 @@ namespace std { %typemap(varin) string { if (gh_string_p($input)) { char *tempptr = SWIG_scm2str($input); - $1 = std::string(tempptr); + $1.assign(tempptr); if (tempptr) SWIG_free(tempptr); } else { SWIG_exception(SWIG_TypeError, "string expected"); diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i index 38e936b04..789e17a65 100644 --- a/Lib/java/std_string.i +++ b/Lib/java/std_string.i @@ -36,7 +36,7 @@ class string; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); if (!$1_pstr) return $null; - $1 = std::string($1_pstr); + $1.assign($1_pstr); jenv->ReleaseStringUTFChars($input, $1_pstr); %} %typemap(directorout) string @@ -46,7 +46,7 @@ class string; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); if (!$1_pstr) return $null; - $result = std::string($1_pstr); + $result.assign($1_pstr); jenv->ReleaseStringUTFChars($input, $1_pstr); %} %typemap(directorin,descriptor="Ljava/lang/String;") string diff --git a/Lib/java/std_wstring.i b/Lib/java/std_wstring.i index d38a62c29..39a6988d1 100644 --- a/Lib/java/std_wstring.i +++ b/Lib/java/std_wstring.i @@ -41,7 +41,7 @@ class wstring; for (jsize i = 0; i < $1_len; ++i) { conv_buf[i] = $1_pstr[i]; } - $1 = std::wstring(conv_buf, $1_len); + $1.assign(conv_buf, $1_len); delete [] conv_buf; } jenv->ReleaseStringChars($input, $1_pstr); @@ -60,7 +60,7 @@ class wstring; for (jsize i = 0; i < $1_len; ++i) { conv_buf[i] = $1_pstr[i]; } - $result = std::wstring(conv_buf, $1_len); + $result.assign(conv_buf, $1_len); delete [] conv_buf; } jenv->ReleaseStringChars($input, $1_pstr); @@ -112,7 +112,7 @@ class wstring; for (jsize i = 0; i < $1_len; ++i) { conv_buf[i] = $1_pstr[i]; } - $1_str = std::wstring(conv_buf, $1_len); + $1_str.assign(conv_buf, $1_len); delete [] conv_buf; } $1 = &$1_str; @@ -133,7 +133,7 @@ class wstring; for (jsize i = 0; i < $1_len; ++i) { conv_buf[i] = $1_pstr[i]; } - $1_str = std::wstring(conv_buf, $1_len); + $1_str.assign(conv_buf, $1_len); delete [] conv_buf; } $result = &$1_str; diff --git a/Lib/mzscheme/std_string.i b/Lib/mzscheme/std_string.i index aa27bc0d8..c9a82efe4 100644 --- a/Lib/mzscheme/std_string.i +++ b/Lib/mzscheme/std_string.i @@ -33,14 +33,14 @@ namespace std { %typemap(in) string { if (SCHEME_STRINGP($input)) - $1 = std::string(SCHEME_STR_VAL($input)); + $1.assign(SCHEME_STR_VAL($input)); else SWIG_exception(SWIG_TypeError, "string expected"); } %typemap(in) const string & (std::string temp) { if (SCHEME_STRINGP($input)) { - temp = std::string(SCHEME_STR_VAL($input)); + temp.assign(SCHEME_STR_VAL($input)); $1 = &temp; } else { SWIG_exception(SWIG_TypeError, "string expected"); diff --git a/Lib/ocaml/std_string.i b/Lib/ocaml/std_string.i index 7908e8877..7add3a070 100644 --- a/Lib/ocaml/std_string.i +++ b/Lib/ocaml/std_string.i @@ -85,16 +85,16 @@ namespace std { /* Overloading check */ %typemap(in) string { if (caml_ptr_check($input)) - $1 = std::string((char *)caml_ptr_val($input,0), - caml_string_len($input)); + $1.assign((char *)caml_ptr_val($input,0), + caml_string_len($input)); else SWIG_exception(SWIG_TypeError, "string expected"); } %typemap(in) const string & (std::string temp) { if (caml_ptr_check($input)) { - temp = std::string((char *)caml_ptr_val($input,0), - caml_string_len($input)); + temp.assign((char *)caml_ptr_val($input,0), + caml_string_len($input)); $1 = &temp; } else { SWIG_exception(SWIG_TypeError, "string expected"); @@ -103,8 +103,8 @@ namespace std { %typemap(in) string & (std::string temp) { if (caml_ptr_check($input)) { - temp = std::string((char *)caml_ptr_val($input,0), - caml_string_len($input)); + temp.assign((char *)caml_ptr_val($input,0), + caml_string_len($input)); $1 = &temp; } else { SWIG_exception(SWIG_TypeError, "string expected"); @@ -131,8 +131,8 @@ namespace std { } %typemap(directorout) string { - $result = std::string((char *)caml_ptr_val($input,0), - caml_string_len($input)); + $result.assign((char *)caml_ptr_val($input,0), + caml_string_len($input)); } %typemap(out) string { diff --git a/Lib/pike/std_string.i b/Lib/pike/std_string.i index e7f9ee03c..ca1fad822 100644 --- a/Lib/pike/std_string.i +++ b/Lib/pike/std_string.i @@ -25,13 +25,13 @@ namespace std { %typemap(in, pikedesc="tStr") string { if ($input.type != T_STRING) Pike_error("Bad argument: Expected a string.\n"); - $1 = std::string(STR0($input.u.string)); + $1.assign(STR0($input.u.string)); } %typemap(in, pikedesc="tStr") const string & (std::string temp) { if ($input.type != T_STRING) Pike_error("Bad argument: Expected a string.\n"); - temp = std::string(STR0($input.u.string)); + temp.assign(STR0($input.u.string)); $1 = &temp; } @@ -45,14 +45,14 @@ namespace std { %typemap(directorout) string { if ($input.type == T_STRING) - $result = std::string(STR0($input.u.string)); + $result.assign(STR0($input.u.string)); else throw Swig::DirectorTypeMismatchException("string expected"); } %typemap(directorout) const string & (std::string temp) { if ($input.type == T_STRING) { - temp = std::string(STR0($input.u.string)); + temp.assign(STR0($input.u.string)); $result = &temp; } else { throw Swig::DirectorTypeMismatchException("string expected");