Bug 891215 (part 16) - Slim down RegExpObject-inl.h. r=terrence.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 09 Jul 2013 13:41:16 -0700
changeset 138441 763c1a2daaee63f011c327790fb2ff066284831b
parent 138440 a8f8b03cdb364e8e7bc8d2215ce832ef1eb80dbb
child 138442 42d3202f0e030a9a2af9661c727ee903f3c2aba3
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersterrence
bugs891215
milestone25.0a1
Bug 891215 (part 16) - Slim down RegExpObject-inl.h. r=terrence.
js/src/vm/MatchPairs.h
js/src/vm/RegExpObject-inl.h
js/src/vm/RegExpObject.h
--- a/js/src/vm/MatchPairs.h
+++ b/js/src/vm/MatchPairs.h
@@ -70,17 +70,27 @@ class MatchPairs
     /* MatchPair buffer allocator: set pairs_ and pairCount_. */
     virtual bool allocOrExpandArray(size_t pairCount) = 0;
 
     bool initArray(size_t pairCount);
     bool initArrayFrom(MatchPairs &copyFrom);
     void forgetArray() { pairs_ = NULL; }
 
     void displace(size_t disp);
-    inline void checkAgainst(size_t length);
+    void checkAgainst(size_t inputLength) {
+#ifdef DEBUG
+        for (size_t i = 0; i < pairCount_; i++) {
+            const MatchPair &p = pair(i);
+            JS_ASSERT(p.check());
+            if (p.isUndefined())
+                continue;
+            JS_ASSERT(size_t(p.limit) <= inputLength);
+        }
+#endif
+    }
 
   public:
     /* Querying functions in the style of RegExpStatics. */
     bool   empty() const           { return pairCount_ == 0; }
     size_t pairCount() const       { JS_ASSERT(pairCount_ > 0); return pairCount_; }
     size_t parenCount() const      { return pairCount_ - 1; }
 
   public:
--- a/js/src/vm/RegExpObject-inl.h
+++ b/js/src/vm/RegExpObject-inl.h
@@ -6,45 +6,18 @@
 
 #ifndef vm_RegExpObject_inl_h
 #define vm_RegExpObject_inl_h
 
 #include "mozilla/Util.h"
 
 #include "vm/RegExpObject.h"
 
-#include "jsstrinlines.h"
-
-#include "vm/String-inl.h"
-
 namespace js {
 
-inline RegExpShared *
-RegExpObject::maybeShared() const
-{
-    return static_cast<RegExpShared *>(JSObject::getPrivate());
-}
-
-inline void
-RegExpObject::shared(RegExpGuard *g) const
-{
-    JS_ASSERT(maybeShared() != NULL);
-    g->init(*maybeShared());
-}
-
-inline bool
-RegExpObject::getShared(ExclusiveContext *cx, RegExpGuard *g)
-{
-    if (RegExpShared *shared = maybeShared()) {
-        g->init(*shared);
-        return true;
-    }
-    return createShared(cx, g);
-}
-
 inline void
 RegExpObject::setShared(ExclusiveContext *cx, RegExpShared &shared)
 {
     shared.prepareForUse(cx);
     JSObject::setPrivate(&shared);
 }
 
 inline void
@@ -84,89 +57,11 @@ RegExpObject::setMultiline(bool enabled)
 }
 
 inline void
 RegExpObject::setSticky(bool enabled)
 {
     setSlot(STICKY_FLAG_SLOT, BooleanValue(enabled));
 }
 
-/* This function should be deleted once bad Android platforms phase out. See bug 604774. */
-inline bool
-RegExpShared::isJITRuntimeEnabled(JSContext *cx)
-{
-#if ENABLE_YARR_JIT
-# if defined(ANDROID)
-    return !cx->jitIsBroken;
-# else
-    return true;
-# endif
-#else
-    return false;
-#endif
-}
-
-inline bool
-RegExpToShared(JSContext *cx, HandleObject obj, RegExpGuard *g)
-{
-    if (obj->is<RegExpObject>())
-        return obj->as<RegExpObject>().getShared(cx, g);
-    return Proxy::regexp_toShared(cx, obj, g);
-}
-
-inline void
-RegExpShared::prepareForUse(ExclusiveContext *cx)
-{
-    gcNumberWhenUsed = cx->gcNumber();
-}
-
-RegExpGuard::RegExpGuard(ExclusiveContext *cx)
-  : re_(NULL), source_(cx)
-{
-}
-
-RegExpGuard::RegExpGuard(ExclusiveContext *cx, RegExpShared &re)
-  : re_(&re), source_(cx, re.source)
-{
-    re_->incRef();
-}
-
-RegExpGuard::~RegExpGuard()
-{
-    release();
-}
-
-inline void
-RegExpGuard::init(RegExpShared &re)
-{
-    JS_ASSERT(!initialized());
-    re_ = &re;
-    re_->incRef();
-    source_ = re_->source;
-}
-
-inline void
-RegExpGuard::release()
-{
-    if (re_) {
-        re_->decRef();
-        re_ = NULL;
-        source_ = NULL;
-    }
-}
-
-inline void
-MatchPairs::checkAgainst(size_t inputLength)
-{
-#ifdef DEBUG
-    for (size_t i = 0; i < pairCount_; i++) {
-        const MatchPair &p = pair(i);
-        JS_ASSERT(p.check());
-        if (p.isUndefined())
-            continue;
-        JS_ASSERT(size_t(p.limit) <= inputLength);
-    }
-#endif
-}
-
 } /* namespace js */
 
 #endif /* vm_RegExpObject_inl_h */
--- a/js/src/vm/RegExpObject.h
+++ b/js/src/vm/RegExpObject.h
@@ -8,16 +8,17 @@
 #define vm_RegExpObject_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 
 #include <stddef.h>
 #include "jscntxt.h"
 #include "jsobj.h"
+#include "jsproxy.h"
 
 #include "gc/Barrier.h"
 #include "gc/Marking.h"
 #include "js/TemplateLib.h"
 #include "vm/MatchPairs.h"
 #include "vm/Runtime.h"
 #include "yarr/MatchResult.h"
 #include "yarr/Yarr.h"
@@ -154,22 +155,36 @@ class RegExpShared
     ~RegExpShared();
 
     /* Explicit trace function for use by the RegExpStatics and JITs. */
     void trace(JSTracer *trc) {
         MarkStringUnbarriered(trc, &source, "regexpshared source");
     }
 
     /* Static functions to expose some Yarr logic. */
-    static inline bool isJITRuntimeEnabled(JSContext *cx);
+
+    // This function should be deleted once bad Android platforms phase out. See bug 604774.
+    static bool isJITRuntimeEnabled(JSContext *cx) {
+        #if ENABLE_YARR_JIT
+        # if defined(ANDROID)
+            return !cx->jitIsBroken;
+        # else
+            return true;
+        # endif
+        #else
+            return false;
+        #endif
+    }
     static void reportYarrError(ExclusiveContext *cx, TokenStream *ts, ErrorCode error);
     static bool checkSyntax(ExclusiveContext *cx, TokenStream *tokenStream, JSLinearString *source);
 
     /* Called when a RegExpShared is installed into a RegExpObject. */
-    inline void prepareForUse(ExclusiveContext *cx);
+    void prepareForUse(ExclusiveContext *cx) {
+        gcNumberWhenUsed = cx->gcNumber();
+    }
 
     /* Primary interface: run this regular expression on the given string. */
     RegExpRunStatus execute(JSContext *cx, const jschar *chars, size_t length,
                             size_t *lastIndex, MatchPairs &matches);
 
     /* Run the regular expression without collecting matches, for test(). */
     RegExpRunStatus executeMatchOnly(JSContext *cx, const jschar *chars, size_t length,
                                      size_t *lastIndex, MatchPair &match);
@@ -214,23 +229,45 @@ class RegExpGuard
      * must remain rooted for the active lifetime of the RegExpShared.
      */
     RootedAtom source_;
 
     RegExpGuard(const RegExpGuard &) MOZ_DELETE;
     void operator=(const RegExpGuard &) MOZ_DELETE;
 
   public:
-    inline RegExpGuard(ExclusiveContext *cx);
-    inline RegExpGuard(ExclusiveContext *cx, RegExpShared &re);
-    inline ~RegExpGuard();
+    RegExpGuard(ExclusiveContext *cx)
+      : re_(NULL), source_(cx)
+    {}
+
+    RegExpGuard(ExclusiveContext *cx, RegExpShared &re)
+      : re_(&re), source_(cx, re.source)
+    {
+        re_->incRef();
+    }
+
+    ~RegExpGuard() {
+        release();
+    }
 
   public:
-    inline void init(RegExpShared &re);
-    inline void release();
+    void init(RegExpShared &re) {
+        JS_ASSERT(!initialized());
+        re_ = &re;
+        re_->incRef();
+        source_ = re_->source;
+    }
+
+    void release() {
+        if (re_) {
+            re_->decRef();
+            re_ = NULL;
+            source_ = NULL;
+        }
+    }
 
     bool initialized() const { return !!re_; }
     RegExpShared *re() const { JS_ASSERT(initialized()); return re_; }
     RegExpShared *operator->() { return re(); }
     RegExpShared &operator*() { return *re(); }
 };
 
 class RegExpCompartment
@@ -341,18 +378,28 @@ class RegExpObject : public JSObject
     inline void setGlobal(bool enabled);
     inline void setMultiline(bool enabled);
     inline void setSticky(bool enabled);
     bool ignoreCase() const { return getSlot(IGNORE_CASE_FLAG_SLOT).toBoolean(); }
     bool global() const     { return getSlot(GLOBAL_FLAG_SLOT).toBoolean(); }
     bool multiline() const  { return getSlot(MULTILINE_FLAG_SLOT).toBoolean(); }
     bool sticky() const     { return getSlot(STICKY_FLAG_SLOT).toBoolean(); }
 
-    inline void shared(RegExpGuard *g) const;
-    inline bool getShared(ExclusiveContext *cx, RegExpGuard *g);
+    void shared(RegExpGuard *g) const {
+        JS_ASSERT(maybeShared() != NULL);
+        g->init(*maybeShared());
+    }
+
+    bool getShared(ExclusiveContext *cx, RegExpGuard *g) {
+        if (RegExpShared *shared = maybeShared()) {
+            g->init(*shared);
+            return true;
+        }
+        return createShared(cx, g);
+    }
     inline void setShared(ExclusiveContext *cx, RegExpShared &shared);
 
   private:
     friend class RegExpObjectBuilder;
 
     /*
      * Compute the initial shape to associate with fresh RegExp objects,
      * encoding their initial properties. Return the shape after
@@ -362,17 +409,19 @@ class RegExpObject : public JSObject
 
     bool init(ExclusiveContext *cx, HandleAtom source, RegExpFlag flags);
 
     /*
      * Precondition: the syntax for |source| has already been validated.
      * Side effect: sets the private field.
      */
     bool createShared(ExclusiveContext *cx, RegExpGuard *g);
-    RegExpShared *maybeShared() const;
+    RegExpShared *maybeShared() const {
+        return static_cast<RegExpShared *>(JSObject::getPrivate());
+    }
 
     /* Call setShared in preference to setPrivate. */
     void setPrivate(void *priv) MOZ_DELETE;
 };
 
 /*
  * Parse regexp flags. Report an error and return false if an invalid
  * sequence of flags is encountered (repeat/invalid flag).
@@ -386,17 +435,22 @@ ParseRegExpFlags(JSContext *cx, JSString
  * Assuming ObjectClassIs(obj, ESClass_RegExp), return obj's RegExpShared.
  *
  * Beware: this RegExpShared can be owned by a compartment other than
  * cx->compartment. Normal RegExpGuard (which is necessary anyways)
  * will protect the object but it is important not to assign the return value
  * to be the private of any RegExpObject.
  */
 inline bool
-RegExpToShared(JSContext *cx, HandleObject obj, RegExpGuard *g);
+RegExpToShared(JSContext *cx, HandleObject obj, RegExpGuard *g)
+{
+    if (obj->is<RegExpObject>())
+        return obj->as<RegExpObject>().getShared(cx, g);
+    return Proxy::regexp_toShared(cx, obj, g);
+}
 
 template<XDRMode mode>
 bool
 XDRScriptRegExpObject(XDRState<mode> *xdr, HeapPtrObject *objp);
 
 extern JSObject *
 CloneScriptRegExpObject(JSContext *cx, RegExpObject &re);