Bug 1278795 - Make morkAtom::AliasYarn() static. r=rkent
authorJorg K <jorgk@jorgk.com>
Tue, 15 Nov 2016 11:09:45 +0100
changeset 20713 f88a5eda49535c043f7b61cb11582b2a7c920b9f
parent 20712 2a2eeac814eed44d5be13fe3c7e868b623b35aa8
child 20714 e8c2d64742f4c6a33ae4463e0b6436dc37edabcb
push id12536
push usermozilla@jorgk.com
push dateTue, 15 Nov 2016 10:17:54 +0000
treeherdercomm-central@f88a5eda4953 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent
bugs1278795
Bug 1278795 - Make morkAtom::AliasYarn() static. r=rkent
db/mork/src/morkAtom.cpp
db/mork/src/morkAtom.h
db/mork/src/morkCell.cpp
db/mork/src/morkCellObject.cpp
db/mork/src/morkRowObject.cpp
db/mork/src/morkStore.cpp
db/mork/src/morkWriter.cpp
--- a/db/mork/src/morkAtom.cpp
+++ b/db/mork/src/morkAtom.cpp
@@ -89,65 +89,23 @@ morkAtom::GetYarn(mdbYarn* outYarn) cons
   {
     outYarn->mYarn_Fill = 0; // tell yarn that atom has no bytes
   }
   outYarn->mYarn_Form = form; // always update the form slot
   
   return ( source != 0 );
 }
 
+/* static */
 mork_bool
-morkAtom::AsBuf(morkBuf& outBuf) const
-{
-  const morkAtom* atom = this;
-  if ( atom )
-  {
-    if ( atom->IsWeeBook() )
-    {
-      morkWeeBookAtom* weeBook = (morkWeeBookAtom*) atom;
-      outBuf.mBuf_Body = weeBook->mWeeBookAtom_Body;
-      outBuf.mBuf_Fill = weeBook->mAtom_Size;
-    }
-    else if ( atom->IsBigBook() )
-    {
-      morkBigBookAtom* bigBook = (morkBigBookAtom*) atom;
-      outBuf.mBuf_Body = bigBook->mBigBookAtom_Body;
-      outBuf.mBuf_Fill = bigBook->mBigBookAtom_Size;
-    }
-    else if ( atom->IsWeeAnon() )
-    {
-      morkWeeAnonAtom* weeAnon = (morkWeeAnonAtom*) atom;
-      outBuf.mBuf_Body = weeAnon->mWeeAnonAtom_Body;
-      outBuf.mBuf_Fill = weeAnon->mAtom_Size;
-    }
-    else if ( atom->IsBigAnon() )
-    {
-      morkBigAnonAtom* bigAnon = (morkBigAnonAtom*) atom;
-      outBuf.mBuf_Body = bigAnon->mBigAnonAtom_Body;
-      outBuf.mBuf_Fill = bigAnon->mBigAnonAtom_Size;
-    }
-    else
-      atom = 0; // show desire to put empty content in yarn
-  }
-  
-  if ( !atom ) // empty content for yarn?
-  {
-    outBuf.mBuf_Body = 0;
-    outBuf.mBuf_Fill = 0;
-  }
-  return ( atom != 0 );
-}
-
-mork_bool
-morkAtom::AliasYarn(mdbYarn* outYarn) const
+morkAtom::AliasYarn(const morkAtom* atom, mdbYarn* outYarn)
 {
   outYarn->mYarn_More = 0;
   outYarn->mYarn_Form = 0;
-  const morkAtom* atom = this;
-  
+
   if ( atom )
   {
     if ( atom->IsWeeBook() )
     {
       morkWeeBookAtom* weeBook = (morkWeeBookAtom*) atom;
       outYarn->mYarn_Buf = weeBook->mWeeBookAtom_Body;
       outYarn->mYarn_Fill = weeBook->mAtom_Size;
       outYarn->mYarn_Size = weeBook->mAtom_Size;
--- a/db/mork/src/morkAtom.h
+++ b/db/mork/src/morkAtom.h
@@ -82,19 +82,18 @@ private: // warnings
 
 public: // errors
 
   static void BadAtomKindError(morkEnv* ev);
   static void ZeroAidError(morkEnv* ev);
   static void AtomSizeOverflowError(morkEnv* ev);
 
 public: // yarns
-  
-  mork_bool   AsBuf(morkBuf& outBuf) const;
-  mork_bool   AliasYarn(mdbYarn* outYarn) const;
+
+  static mork_bool AliasYarn(const morkAtom* atom, mdbYarn* outYarn);
   mork_bool   GetYarn(mdbYarn* outYarn) const;
 
 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
@@ -47,20 +47,19 @@ morkCell::GetYarn(morkEnv* ev, mdbYarn* 
   MORK_USED_1(ev);
   mCell_Atom->GetYarn(outYarn);
 }
 
 void
 morkCell::AliasYarn(morkEnv* ev, mdbYarn* outYarn) const
 {
   MORK_USED_1(ev);
-  mCell_Atom->AliasYarn(outYarn);
+  morkAtom::AliasYarn(mCell_Atom, outYarn);
 }
-  
-  
+
 void
 morkCell::SetCellClean()
 {
   mork_column col = this->GetColumn();
   this->SetColumnAndChange(col, morkChange_kNil);
 }
   
 void
--- a/db/mork/src/morkCellObject.cpp
+++ b/db/mork/src/morkCellObject.cpp
@@ -345,20 +345,20 @@ NS_IMETHODIMP morkCellObject::AliasYarn(
 {
   nsresult outErr = NS_OK;
   morkCell* cell = 0;
   morkEnv* ev = this->CanUseCell(mev, /*inMutable*/ morkBool_kTrue,
     &outErr, &cell);
   if ( ev )
   {
     morkAtom* atom = cell->GetAtom();
-    atom->AliasYarn(outYarn);
+    morkAtom::AliasYarn(atom, outYarn);
     outErr = ev->AsErr();
   }
-    
+
   return outErr;
 } // writes ALL yarn slots
 
 // } ----- end attribute methods -----
 
 // } ===== end nsIMdbBlob methods =====
 
 // { ===== begin nsIMdbCell methods =====
--- a/db/mork/src/morkRowObject.cpp
+++ b/db/mork/src/morkRowObject.cpp
@@ -323,18 +323,18 @@ morkRowObject::AddCell( // copy a cell f
         {
           morkStore* store = mRowObject_Row->GetRowSpaceStore(ev);
           morkStore* cellStore = cellRow->GetRowSpaceStore(ev);
           if ( store && cellStore )
           {
             mork_column col = cell->GetColumn();
             morkAtom* atom = cell->mCell_Atom;
             mdbYarn yarn;
-            atom->AliasYarn(&yarn); // works even when atom is nil
-            
+            morkAtom::AliasYarn(atom, &yarn); // works even when atom is nil
+
             if ( store != cellStore )
               col = store->CopyToken(ev, col, cellStore);
             if ( ev->Good() )
               AddColumn(ev, col, &yarn);
           }
           else
             ev->NilPointerError();
         }
@@ -484,17 +484,17 @@ morkRowObject::AliasCellYarn(
 {
   nsresult outErr = NS_OK;
   morkEnv* ev = morkEnv::FromMdbEnv(mev);
   if ( ev )
   {
     if ( mRowObject_Store && mRowObject_Row)
     {
       morkAtom* atom = mRowObject_Row->GetColumnAtom(ev, inColumn);
-      atom->AliasYarn(outYarn);
+      morkAtom::AliasYarn(atom, outYarn);
       // note nil atom works and sets yarn correctly
     }
     outErr = ev->AsErr();
   }
   return outErr;
 }
 
 NS_IMETHODIMP
--- a/db/mork/src/morkStore.cpp
+++ b/db/mork/src/morkStore.cpp
@@ -651,22 +651,22 @@ morkStore::CreateStoreFile(morkEnv* ev,
 morkAtom*
 morkStore::CopyAtom(morkEnv* ev, const morkAtom* inAtom)
 // copy inAtom (from some other store) over to this store
 {
   morkAtom* outAtom = 0;
   if ( inAtom )
   {
     mdbYarn yarn;
-    if ( inAtom->AliasYarn(&yarn) )
+    if ( morkAtom::AliasYarn(inAtom, &yarn) )
       outAtom = this->YarnToAtom(ev, &yarn, true /* create */);
   }
   return outAtom;
 }
- 
+
 morkAtom*
 morkStore::YarnToAtom(morkEnv* ev, const mdbYarn* inYarn, bool createIfMissing /* = true */)
 {
   morkAtom* outAtom = 0;
   if ( ev->Good() )
   {
     morkAtomSpace* groundSpace = this->LazyGetGroundAtomSpace(ev);
     if ( groundSpace )
--- a/db/mork/src/morkWriter.cpp
+++ b/db/mork/src/morkWriter.cpp
@@ -432,17 +432,17 @@ mork_size
 morkWriter::WriteAtom(morkEnv* ev, const morkAtom* inAtom)
   // return number of atom bytes written on the current line (which
   // implies that escaped line breaks will make the size value smaller
   // than the entire atom's size, since only part goes on a last line).
 {
   mork_size outSize = 0;
   mdbYarn yarn; // to ref content inside atom
 
-  if ( inAtom->AliasYarn(&yarn) )
+  if ( morkAtom::AliasYarn(inAtom, &yarn) )
   {
     if ( mWriter_DidStartDict && yarn.mYarn_Form != mWriter_DictForm )
       this->ChangeDictForm(ev, yarn.mYarn_Form);  
       
     outSize = this->WriteYarn(ev, &yarn);
     // mWriter_LineSize += stream->Write(ev, inYarn->mYarn_Buf, outSize);
   }
   else
@@ -484,20 +484,20 @@ morkWriter::WriteAtomSpaceAsDict(morkEnv
     for ( c = ai->FirstAtom(ev, &atom); c && ev->Good();
           c = ai->NextAtom(ev, &atom) )
     {
       if ( atom )
       {
         if ( atom->IsAtomDirty() )
         {
           atom->SetAtomClean(); // neutralize change
-          
-          atom->AliasYarn(&yarn);
+
+          morkAtom::AliasYarn(atom, &yarn);
           mork_size size = ev->TokenAsHex(idBuf, atom->mBookAtom_Id);
-          
+
           if ( yarn.mYarn_Form != mWriter_DictForm )
             this->ChangeDictForm(ev, yarn.mYarn_Form);
 
           mork_size pending = yarn.mYarn_Fill + size + 
             morkWriter_kYarnEscapeSlop + 4;
           this->IndentOverMaxLine(ev, pending, morkWriter_kDictAliasDepth);
           mork_size bytesWritten;
           stream->Write(mdbev, buf, size+1, &bytesWritten); //  + '('
@@ -1860,17 +1860,17 @@ morkWriter::PutRowDict(morkEnv* ev, mork
           
           this->IndentAsNeeded(ev, morkWriter_kDictAliasDepth);
           morkBookAtom* ba = (morkBookAtom*) atom;
           mork_size size = ev->TokenAsHex(idBuf, ba->mBookAtom_Id);
           mork_size bytesWritten;
           stream->Write(ev->AsMdbEnv(), buf, size+1, &bytesWritten); // '('
           mWriter_LineSize += bytesWritten;
 
-          if ( atom->AliasYarn(&yarn) )
+          if ( morkAtom::AliasYarn(atom, &yarn) )
           {
             mork_scope atomScope = atom->GetBookAtomSpaceScope(ev);
             if ( atomScope && atomScope != mWriter_DictAtomScope )
               this->ChangeDictAtomScope(ev, atomScope);
             
             if ( mWriter_DidStartDict && yarn.mYarn_Form != mWriter_DictForm )
               this->ChangeDictForm(ev, yarn.mYarn_Form);  
       
@@ -1914,44 +1914,44 @@ morkWriter::IsYarnAllValue(const mdbYarn
 
 mork_bool
 morkWriter::PutVerboseCell(morkEnv* ev, morkCell* ioCell, mork_bool inWithVal)
 {
   morkStream* stream = mWriter_Stream;
   morkStore* store = mWriter_Store;
 
   mdbYarn* colYarn = &mWriter_ColYarn;
-  
+
   morkAtom* atom = (inWithVal)? ioCell->GetAtom() : (morkAtom*) 0;
-  
+
   mork_column col = ioCell->GetColumn();
   store->TokenToString(ev, col, colYarn);
-  
+
   mdbYarn yarn; // to ref content inside atom
-  atom->AliasYarn(&yarn); // works even when atom==nil
-  
+  morkAtom::AliasYarn(atom, &yarn); // works even when atom==nil
+
   if ( yarn.mYarn_Form != mWriter_RowForm )
     this->ChangeRowForm(ev, yarn.mYarn_Form);
 
   mork_size pending = yarn.mYarn_Fill + colYarn->mYarn_Fill +
      morkWriter_kYarnEscapeSlop + 3;
   this->IndentOverMaxLine(ev, pending, morkWriter_kRowCellDepth);
 
   stream->Putc(ev, '('); // start cell
   ++mWriter_LineSize;
 
   this->WriteYarn(ev, colYarn); // column
-  
+
   pending = yarn.mYarn_Fill + morkWriter_kYarnEscapeSlop;
   this->IndentOverMaxLine(ev, pending, morkWriter_kRowCellValueDepth);
   stream->Putc(ev, '=');
   ++mWriter_LineSize;
-  
+
   this->WriteYarn(ev, &yarn); // value
-  
+
   stream->Putc(ev, ')'); // end cell
   ++mWriter_LineSize;
 
   return ev->Good();
 }
 
 mork_bool
 morkWriter::PutVerboseRowCells(morkEnv* ev, morkRow* ioRow)
@@ -1988,21 +1988,21 @@ morkWriter::PutCell(morkEnv* ev, morkCel
   morkAtom* atom = (inWithVal)? ioCell->GetAtom() : (morkAtom*) 0;
   
   mork_column col = ioCell->GetColumn();
   char* p = idBuf;
   colSize = ev->TokenAsHex(p, col);
   p += colSize;
 
   mdbYarn yarn; // to ref content inside atom
-  atom->AliasYarn(&yarn); // works even when atom==nil
-  
+  morkAtom::AliasYarn(atom, &yarn); // works even when atom==nil
+
   if ( yarn.mYarn_Form != mWriter_RowForm )
     this->ChangeRowForm(ev, yarn.mYarn_Form);
-  
+
   if ( atom && atom->IsBook() ) // is it possible to write atom ID?
   {
     this->IndentAsNeeded(ev, morkWriter_kRowCellDepth);
     *p++ = '^';
     morkBookAtom* ba = (morkBookAtom*) atom;
 
     mork_size valSize = ev->TokenAsHex(p, ba->mBookAtom_Id);
     mork_fill yarnFill = yarn.mYarn_Fill;