I would explicitly compare length == 0, but other than that it LGTM.

On Thu, Mar 19, 2009 at 4:01 PM,  <[email protected]> wrote:
>
> Reviewers: Kasper Lund,
>
> Description:
> Add a public API for using an empty sring.
>
> v8::String::Empty()
>
>
>
> Please review this at http://codereview.chromium.org/42423
>
> SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
>
> Affected files:
>   M     include/v8.h
>   M     src/api.cc
>
>
> Index: include/v8.h
> ===================================================================
> --- include/v8.h        (revision 1555)
> +++ include/v8.h        (working copy)
> @@ -736,6 +736,11 @@
>    int WriteUtf8(char* buffer, int length = -1) const; // UTF-8
>
>    /**
> +   * A zero length string.
> +   */
> +  static v8::Local<v8::String> Empty();
> +
> +  /**
>     * Returns true if the string is external
>     */
>    bool IsExternal() const;
> Index: src/api.cc
> ===================================================================
> --- src/api.cc  (revision 1555)
> +++ src/api.cc  (working copy)
> @@ -2472,9 +2472,17 @@
>  }
>
>
> +Local<String> v8::String::Empty() {
> +  EnsureInitialized("v8::String::Empty()");
> +  LOG_API("String::Empty()");
> +  return Utils::ToLocal(i::Factory::empty_symbol());
> +}
> +
> +
>  Local<String> v8::String::New(const char* data, int length) {
>    EnsureInitialized("v8::String::New()");
>    LOG_API("String::New(char)");
> +  if (!length) return Empty();
>    if (length == -1) length = strlen(data);
>    i::Handle<i::String> result =
>        i::Factory::NewStringFromUtf8(i::Vector<const char>(data, length));
> @@ -2503,6 +2511,7 @@
>  Local<String> v8::String::New(const uint16_t* data, int length) {
>    EnsureInitialized("v8::String::New()");
>    LOG_API("String::New(uint16_)");
> +  if (!length) return Empty();
>    if (length == -1) length = TwoByteStringLength(data);
>    i::Handle<i::String> result =
>        i::Factory::NewStringFromTwoByte(i::Vector<const uint16_t>(data,
> length));
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to