Bug 1568095 - Make morkAtom::GetYarn() static. r=benc a=jorgk
authorJorg K <jorgk@jorgk.com>
Fri, 26 Jul 2019 21:20:49 +0200
changeset 35267 71349d370678bb201e7566a6e83950ac58385496
parent 35266 cfe5da4d82fe0fe9aff0e4cf551f891d46d331ae
child 35268 160f774b6e653cf0b968120459c987c587dfff36
push id2475
push usermozilla@jorgk.com
push dateFri, 02 Aug 2019 20:07:29 +0000
treeherdercomm-beta@c7b7a4c6679d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc, jorgk
bugs1568095
Bug 1568095 - Make morkAtom::GetYarn() static. r=benc a=jorgk
db/mork/src/morkAtom.cpp
db/mork/src/morkAtom.h
db/mork/src/morkCell.cpp
db/mork/src/morkCellObject.cpp
db/mork/src/morkRow.cpp
db/mork/src/morkRowObject.cpp
db/mork/src/morkStore.cpp
--- a/db/mork/src/morkAtom.cpp
+++ b/db/mork/src/morkAtom.cpp
@@ -24,40 +24,43 @@
 #endif
 
 #ifndef _MORKATOMSPACE_
 #  include "morkAtomSpace.h"
 #endif
 
 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
-mork_bool morkAtom::GetYarn(mdbYarn* outYarn) const {
+/* static */
+mork_bool morkAtom::GetYarn(const morkAtom* atom, mdbYarn* outYarn) {
   const void* source = 0;
   mdb_fill fill = 0;
   mdb_cscode form = 0;
   outYarn->mYarn_More = 0;
 
-  if (this->IsWeeBook()) {
-    morkWeeBookAtom* weeBook = (morkWeeBookAtom*)this;
-    source = weeBook->mWeeBookAtom_Body;
-    fill = weeBook->mAtom_Size;
-  } else if (this->IsBigBook()) {
-    morkBigBookAtom* bigBook = (morkBigBookAtom*)this;
-    source = bigBook->mBigBookAtom_Body;
-    fill = bigBook->mBigBookAtom_Size;
-    form = bigBook->mBigBookAtom_Form;
-  } else if (this->IsWeeAnon()) {
-    morkWeeAnonAtom* weeAnon = (morkWeeAnonAtom*)this;
-    source = weeAnon->mWeeAnonAtom_Body;
-    fill = weeAnon->mAtom_Size;
-  } else if (this->IsBigAnon()) {
-    morkBigAnonAtom* bigAnon = (morkBigAnonAtom*)this;
-    source = bigAnon->mBigAnonAtom_Body;
-    fill = bigAnon->mBigAnonAtom_Size;
-    form = bigAnon->mBigAnonAtom_Form;
+  if (atom) {
+    if (atom->IsWeeBook()) {
+      morkWeeBookAtom* weeBook = (morkWeeBookAtom*)atom;
+      source = weeBook->mWeeBookAtom_Body;
+      fill = weeBook->mAtom_Size;
+    } else if (atom->IsBigBook()) {
+      morkBigBookAtom* bigBook = (morkBigBookAtom*)atom;
+      source = bigBook->mBigBookAtom_Body;
+      fill = bigBook->mBigBookAtom_Size;
+      form = bigBook->mBigBookAtom_Form;
+    } else if (atom->IsWeeAnon()) {
+      morkWeeAnonAtom* weeAnon = (morkWeeAnonAtom*)atom;
+      source = weeAnon->mWeeAnonAtom_Body;
+      fill = weeAnon->mAtom_Size;
+    } else if (atom->IsBigAnon()) {
+      morkBigAnonAtom* bigAnon = (morkBigAnonAtom*)atom;
+      source = bigAnon->mBigAnonAtom_Body;
+      fill = bigAnon->mBigAnonAtom_Size;
+      form = bigAnon->mBigAnonAtom_Form;
+    }
   }
 
   if (source && fill)  // have an atom with nonempty content?
   {
     // if we have too many bytes, and yarn seems growable:
     if (fill > outYarn->mYarn_Size && outYarn->mYarn_Grow)  // try grow?
       (*outYarn->mYarn_Grow)(outYarn, (mdb_size)fill);      // request bigger
 
--- a/db/mork/src/morkAtom.h
+++ b/db/mork/src/morkAtom.h
@@ -78,17 +78,17 @@ class morkAtom {  //
 
  public:  // errors
   static void BadAtomKindError(morkEnv* ev);
   static void ZeroAidError(morkEnv* ev);
   static void AtomSizeOverflowError(morkEnv* ev);
 
  public:  // yarns
   static mork_bool AliasYarn(const morkAtom* atom, mdbYarn* outYarn);
-  mork_bool GetYarn(mdbYarn* outYarn) const;
+  static mork_bool GetYarn(const morkAtom* atom, mdbYarn* outYarn);
 
  private:  // copying is not allowed
   morkAtom(const morkAtom& other);
   morkAtom& operator=(const morkAtom& other);
 };
 
 /*| OidAtom: an atom that references a row or table by identity.
 |*/
--- a/db/mork/src/morkCell.cpp
+++ b/db/mork/src/morkCell.cpp
@@ -35,17 +35,17 @@
 
 void morkCell::SetYarn(morkEnv* ev, const mdbYarn* inYarn, morkStore* ioStore) {
   morkAtom* atom = ioStore->YarnToAtom(ev, inYarn, true /* create */);
   if (atom) this->SetAtom(ev, atom, ioStore->StorePool());  // refcounts atom
 }
 
 void morkCell::GetYarn(morkEnv* ev, mdbYarn* outYarn) const {
   MORK_USED_1(ev);
-  mCell_Atom->GetYarn(outYarn);
+  morkAtom::GetYarn(mCell_Atom, outYarn);
 }
 
 void morkCell::AliasYarn(morkEnv* ev, mdbYarn* outYarn) const {
   MORK_USED_1(ev);
   morkAtom::AliasYarn(mCell_Atom, outYarn);
 }
 
 void morkCell::SetCellClean() {
--- a/db/mork/src/morkCellObject.cpp
+++ b/db/mork/src/morkCellObject.cpp
@@ -267,17 +267,17 @@ NS_IMETHODIMP morkCellObject::SetYarn(ns
 
 NS_IMETHODIMP morkCellObject::GetYarn(nsIMdbEnv* mev, mdbYarn* outYarn) {
   nsresult outErr = NS_OK;
   morkCell* cell = 0;
   morkEnv* ev =
       this->CanUseCell(mev, /*inMutable*/ morkBool_kTrue, &outErr, &cell);
   if (ev) {
     morkAtom* atom = cell->GetAtom();
-    atom->GetYarn(outYarn);
+    morkAtom::GetYarn(atom, outYarn);
     outErr = ev->AsErr();
   }
 
   return outErr;
 }  // writes some yarn slots
 // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
 
 NS_IMETHODIMP morkCellObject::AliasYarn(nsIMdbEnv* mev, mdbYarn* outYarn) {
--- a/db/mork/src/morkRow.cpp
+++ b/db/mork/src/morkRow.cpp
@@ -369,44 +369,43 @@ morkCell* morkRow::NewCell(morkEnv* ev, 
 }
 
 void morkRow::SeekColumn(morkEnv* ev, mdb_pos inPos, mdb_column* outColumn,
                          mdbYarn* outYarn) {
   morkCell* cells = mRow_Cells;
   if (cells && inPos < mRow_Length && inPos >= 0) {
     morkCell* c = cells + inPos;
     if (outColumn) *outColumn = c->GetColumn();
-    if (outYarn) c->mCell_Atom->GetYarn(outYarn);  // nil atom works okay here
+    if (outYarn) morkAtom::GetYarn(c->mCell_Atom, outYarn);
   } else {
     if (outColumn) *outColumn = 0;
-    if (outYarn) ((morkAtom*)0)->GetYarn(outYarn);  // yes this will work
+    if (outYarn) morkAtom::GetYarn((morkAtom*)0, outYarn);
   }
 }
 
 void morkRow::NextColumn(morkEnv* ev, mdb_column* ioColumn, mdbYarn* outYarn) {
   morkCell* cells = mRow_Cells;
   if (cells) {
     mork_column last = 0;
     mork_column inCol = *ioColumn;
     morkCell* end = cells + mRow_Length;
     while (cells < end) {
       if (inCol == last)  // found column?
       {
-        if (outYarn)
-          cells->mCell_Atom->GetYarn(outYarn);  // nil atom works okay here
+        if (outYarn) morkAtom::GetYarn(cells->mCell_Atom, outYarn);
         *ioColumn = cells->GetColumn();
         return;  // stop, we are done
       } else {
         last = cells->GetColumn();
         ++cells;
       }
     }
   }
   *ioColumn = 0;
-  if (outYarn) ((morkAtom*)0)->GetYarn(outYarn);  // yes this will work
+  if (outYarn) morkAtom::GetYarn((morkAtom*)0, outYarn);
 }
 
 morkCell* morkRow::CellAt(morkEnv* ev, mork_pos inPos) const {
   MORK_USED_1(ev);
   morkCell* cells = mRow_Cells;
   if (cells && inPos < mRow_Length && inPos >= 0) {
     return cells + inPos;
   }
--- a/db/mork/src/morkRowObject.cpp
+++ b/db/mork/src/morkRowObject.cpp
@@ -391,18 +391,17 @@ morkRowObject::GetCellYarn(nsIMdbEnv* me
                            mdbYarn* outYarn)     // writes some yarn slots
 // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
 {
   nsresult outErr = NS_OK;
   morkEnv* ev = morkEnv::FromMdbEnv(mev);
   if (ev) {
     if (mRowObject_Store && mRowObject_Row) {
       morkAtom* atom = mRowObject_Row->GetColumnAtom(ev, inColumn);
-      atom->GetYarn(outYarn);
-      // note nil atom works and sets yarn correctly
+      morkAtom::GetYarn(atom, outYarn);
     }
 
     outErr = ev->AsErr();
   }
   return outErr;
 }
 
 NS_IMETHODIMP
--- a/db/mork/src/morkStore.cpp
+++ b/db/mork/src/morkStore.cpp
@@ -668,17 +668,17 @@ mork_bool morkStore::OidToYarn(morkEnv* 
   morkBookAtom* atom = 0;
 
   morkAtomSpace* atomSpace =
       mStore_AtomSpaces.GetAtomSpace(ev, inOid.mOid_Scope);
   if (atomSpace) {
     morkAtomAidMap* map = &atomSpace->mAtomSpace_AtomAids;
     atom = map->GetAid(ev, (mork_aid)inOid.mOid_Id);
   }
-  atom->GetYarn(outYarn);  // note this is safe even when atom==nil
+  morkAtom::GetYarn(atom, outYarn);
 
   return ev->Good();
 }
 
 morkBookAtom* morkStore::MidToAtom(morkEnv* ev, const morkMid& inMid) {
   morkBookAtom* outAtom = 0;
   mdbOid oid;
   if (this->MidToOid(ev, inMid, &oid)) {
@@ -711,17 +711,17 @@ morkBookAtom* morkStore::MidToAtom(morkE
 
 void morkStore::TokenToString(morkEnv* ev, mdb_token inToken,
                               mdbYarn* outTokenName) {
   if (inToken > morkAtomSpace_kMaxSevenBitAid) {
     morkBookAtom* atom = 0;
     morkAtomSpace* space = mStore_GroundColumnSpace;
     if (space) atom = space->mAtomSpace_AtomAids.GetAid(ev, (mork_aid)inToken);
 
-    atom->GetYarn(outTokenName);  // note this is safe even when atom==nil
+    morkAtom::GetYarn(atom, outTokenName);
   } else  // token is an "immediate" single byte string representation?
     this->SmallTokenToOneByteYarn(ev, inToken, outTokenName);
 }
 
 // void
 // morkStore::SyncTokenIdChange(morkEnv* ev, const morkBookAtom* inAtom,
 //   const mdbOid* inOid)
 // {