[x265] use std::swap() for readability

Deepthi Nandakumar deepthi at multicorewareinc.com
Wed Jul 9 12:16:27 CEST 2014


Hello,

We spent a bunch of effort last year to remove STL dependencies, since they
cause serious trouble between different compilers (even between different
compiler versions).  This is especially since a lot of users will use x265
as a static library.

Thanks,
Deepthi


On Wed, Jul 9, 2014 at 3:00 PM, Satoshi Nakagawa <nakagawa424 at oki.com>
wrote:

> # HG changeset patch
> # User Satoshi Nakagawa <nakagawa424 at oki.com>
> # Date 1404898046 -32400
> #      Wed Jul 09 18:27:26 2014 +0900
> # Node ID a3f4317f4acd89b7ef9bb8616068f9e4ff24328c
> # Parent  644773b8532929a30f910fd269f521e44621f2f7
> use std::swap() for readability
>
> diff -r 644773b85329 -r a3f4317f4acd
> source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
> --- a/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp        Wed Jul 09
> 13:55:42 2014 +0530
> +++ b/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp        Wed Jul 09
> 18:27:26 2014 +0900
> @@ -535,12 +535,10 @@
>      int isChroma = (yCbCr != 0) ? 1 : 0;
>      int shift;
>      int cuHeightTmp;
> -    pixel* tmpLSwap;
>      pixel* tmpL;
>      pixel* tmpU;
>      pixel* clipTbl = NULL;
>      int32_t *offsetBo = NULL;
> -    int32_t *tmp_swap;
>
>      picWidthTmp  = (isChroma == 0) ? m_picWidth  : m_picWidth  >>
> m_hChromaShift;
>      picHeightTmp = (isChroma == 0) ? m_picHeight : m_picHeight >>
> m_vChromaShift;
> @@ -707,9 +705,7 @@
>
>              m_upBufft[startX] = signDown2;
>
> -            tmp_swap  = m_upBuff1;
> -            m_upBuff1 = m_upBufft;
> -            m_upBufft = tmp_swap;
> +            std::swap(m_upBuff1, m_upBufft);
>
>              rec += stride;
>          }
> @@ -775,9 +771,7 @@
>
>  //   if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1)
>      {
> -        tmpLSwap = m_tmpL1;
> -        m_tmpL1  = m_tmpL2;
> -        m_tmpL2  = tmpLSwap;
> +        std::swap(m_tmpL1, m_tmpL2);
>      }
>  }
>
> @@ -864,7 +858,6 @@
>      int frameWidthInCU = m_pic->getFrameWidthInCU();
>      int frameHeightInCU = m_pic->getFrameHeightInCU();
>      int stride;
> -    pixel *tmpUSwap;
>      int sChroma = (yCbCr == 0) ? 0 : 1;
>      bool mergeLeftFlag;
>      int saoBitIncrease = (yCbCr == 0) ? m_saoBitIncreaseY :
> m_saoBitIncreaseC;
> @@ -976,9 +969,7 @@
>              }
>          }
>
> -        tmpUSwap       = m_tmpU1[yCbCr];
> -        m_tmpU1[yCbCr] = m_tmpU2[yCbCr];
> -        m_tmpU2[yCbCr] = tmpUSwap;
> +        std::swap(m_tmpU1[yCbCr], m_tmpU2[yCbCr]);
>      }
>  }
>
> @@ -1018,7 +1009,6 @@
>      int addr;
>      int frameWidthInCU = m_pic->getFrameWidthInCU();
>      int stride;
> -    pixel *tmpUSwap;
>      int sChroma = (yCbCr == 0) ? 0 : 1;
>      bool mergeLeftFlag;
>      int saoBitIncrease = (yCbCr == 0) ? m_saoBitIncreaseY :
> m_saoBitIncreaseC;
> @@ -1122,9 +1112,7 @@
>              }
>          }
>
> -        tmpUSwap       = m_tmpU1[yCbCr];
> -        m_tmpU1[yCbCr] = m_tmpU2[yCbCr];
> -        m_tmpU2[yCbCr] = tmpUSwap;
> +        std::swap(m_tmpU1[yCbCr], m_tmpU2[yCbCr]);
>      }
>  }
>
> diff -r 644773b85329 -r a3f4317f4acd source/Lib/TLibEncoder/TEncCu.cpp
> --- a/source/Lib/TLibEncoder/TEncCu.cpp Wed Jul 09 13:55:42 2014 +0530
> +++ b/source/Lib/TLibEncoder/TEncCu.cpp Wed Jul 09 18:27:26 2014 +0900
> @@ -1258,22 +1258,11 @@
>                      uint64_t bestCost = m_rdCost->psyRdEnabled() ?
> outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
>                      if (tempCost < bestCost)
>                      {
> -                        TComDataCU* tmp = outTempCU;
> -                        outTempCU = outBestCU;
> -                        outBestCU = tmp;
> -
> -                        // Change Prediction data
> -                        TComYuv* yuv = NULL;
> -                        yuv = outBestPredYuv;
> -                        outBestPredYuv = m_tmpPredYuv[depth];
> -                        m_tmpPredYuv[depth] = yuv;
> -
> -                        yuv = rpcYuvReconBest;
> -                        rpcYuvReconBest = m_tmpRecoYuv[depth];
> -                        m_tmpRecoYuv[depth] = yuv;
> -
> +                        std::swap(outBestCU, outTempCU);
> +                        std::swap(outBestPredYuv, m_tmpPredYuv[depth]);
> +                        std::swap(rpcYuvReconBest, m_tmpRecoYuv[depth]);
>
>  m_rdSbacCoders[depth][CI_TEMP_BEST]->store(m_rdSbacCoders[depth][CI_NEXT_BEST]);
> -                    }
> +                    }
>                      outTempCU->setQPSubParts(origQP, 0, depth);
>                      outTempCU->setSkipFlagSubParts(false, 0, depth);
>                      if (!bestIsSkip)
> @@ -1446,21 +1435,14 @@
>
>      if (tempCost < bestCost)
>      {
> -        TComYuv* yuv;
>          // Change Information data
> -        TComDataCU* cu = outBestCU;
> -        outBestCU = outTempCU;
> -        outTempCU = cu;
> +        std::swap(outBestCU, outTempCU);
>
>          // Change Prediction data
> -        yuv = m_bestPredYuv[depth];
> -        m_bestPredYuv[depth] = m_tmpPredYuv[depth];
> -        m_tmpPredYuv[depth] = yuv;
> +        std::swap(m_bestPredYuv[depth], m_tmpPredYuv[depth]);
>
>          // Change Reconstruction data
> -        yuv = m_bestRecoYuv[depth];
> -        m_bestRecoYuv[depth] = m_tmpRecoYuv[depth];
> -        m_tmpRecoYuv[depth] = yuv;
> +        std::swap(m_bestRecoYuv[depth], m_tmpRecoYuv[depth]);
>
>
>  m_rdSbacCoders[depth][CI_TEMP_BEST]->store(m_rdSbacCoders[depth][CI_NEXT_BEST]);
>      }
> diff -r 644773b85329 -r a3f4317f4acd
> source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
> --- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp       Wed Jul 09
> 13:55:42 2014 +0530
> +++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp       Wed Jul 09
> 18:27:26 2014 +0900
> @@ -566,7 +566,6 @@
>      int iEndX;
>      int iEndY;
>      pixel* pTableBo = (yCbCr == 0) ? m_lumaTableBo : m_chromaTableBo;
> -    int32_t *tmp_swap;
>
>      int iIsChroma = (yCbCr != 0) ? 1 : 0;
>      int numSkipLine = iIsChroma ? 4 - (2 * m_vChromaShift) : 4;
> @@ -756,9 +755,7 @@
>                  }
>
>                  m_upBufft[iStartX] = iSignDown2;
> -                tmp_swap  = m_upBuff1;
> -                m_upBuff1 = m_upBufft;
> -                m_upBufft = tmp_swap;
> +                std::swap(m_upBuff1, m_upBufft);
>
>                  pRec += stride;
>                  fenc += stride;
> @@ -844,7 +841,6 @@
>      uint32_t lPelX, tPelY;
>      TComDataCU *pTmpCu;
>      pixel* pTableBo;
> -    int32_t *tmp_swap;
>
>      // NOTE: Row
>      {
> @@ -1054,9 +1050,7 @@
>                      }
>
>                      m_upBufft[firstX] = signDown2;
> -                    tmp_swap  = m_upBuff1;
> -                    m_upBuff1 = m_upBufft;
> -                    m_upBufft = tmp_swap;
> +                    std::swap(m_upBuff1, m_upBufft);
>
>                      pRec += stride;
>                      fenc += stride;
> diff -r 644773b85329 -r a3f4317f4acd source/encoder/compress.cpp
> --- a/source/encoder/compress.cpp       Wed Jul 09 13:55:42 2014 +0530
> +++ b/source/encoder/compress.cpp       Wed Jul 09 18:27:26 2014 +0900
> @@ -280,13 +280,9 @@
>              if (outTempCU->m_totalRDCost < outBestCU->m_totalRDCost)
>              {
>                  bestMergeCand = mergeCand;
> -                TComDataCU* tmp = outTempCU;
> -                outTempCU = outBestCU;
> -                outBestCU = tmp;
> +                std::swap(outBestCU, outTempCU);
>                  // Change Prediction data
> -                TComYuv* yuv = bestPredYuv;
> -                bestPredYuv = m_tmpPredYuv[depth];
> -                m_tmpPredYuv[depth] = yuv;
> +                std::swap(bestPredYuv, m_tmpPredYuv[depth]);
>              }
>          }
>      }
> @@ -308,7 +304,6 @@
>          outTempCU->m_totalRDCost =
> m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion,
> outTempCU->m_totalBits);
>          outTempCU->m_sa8dCost = outTempCU->m_totalRDCost;
>          outBestCU->m_sa8dCost = outTempCU->m_sa8dCost;
> -        TComYuv* yuv;
>          if (m_param->rdLevel >= 1)
>          {
>              //calculate the motion compensation for chroma for the best
> mode selected
> @@ -327,9 +322,7 @@
>                  //No-residue mode
>                  m_search->encodeResAndCalcRdInterCU(outBestCU,
> m_origYuv[depth], bestPredYuv, m_tmpResiYuv[depth], m_bestResiYuv[depth],
> m_tmpRecoYuv[depth], true, true);
>
> -                yuv = yuvReconBest;
> -                yuvReconBest = m_tmpRecoYuv[depth];
> -                m_tmpRecoYuv[depth] = yuv;
> +                std::swap(yuvReconBest, m_tmpRecoYuv[depth]);
>              }
>
>              //Encode with residue
> @@ -339,13 +332,8 @@
>              uint64_t bestCost = m_rdCost->psyRdEnabled() ?
> outBestCU->m_totalPsyCost : outBestCU->m_totalRDCost;
>              if (tempCost < bestCost) //Choose best from no-residue mode
> and residue mode
>              {
> -                TComDataCU* tmp = outTempCU;
> -                outTempCU = outBestCU;
> -                outBestCU = tmp;
> -
> -                yuv = yuvReconBest;
> -                yuvReconBest = m_tmpRecoYuv[depth];
> -                m_tmpRecoYuv[depth] = yuv;
> +                std::swap(outBestCU, outTempCU);
> +                std::swap(yuvReconBest, m_tmpRecoYuv[depth]);
>              }
>          }
>      }
> @@ -391,7 +379,6 @@
>          m_origYuv[depth]->copyToPicYuv(pic->getPicYuvRec(),
> cu->getAddr(), 0);
>      }
>      // We need to split, so don't try these modes.
> -    TComYuv* tempYuv = NULL;
>  #if TOPSKIP
>      if (bInsidePicture && !bInsidePictureParent)
>      {
> @@ -462,9 +449,7 @@
>                      xComputeCostInter(m_interCU_2Nx2N[depth],
> m_modePredYuv[0][depth], SIZE_2Nx2N);
>                      /* Choose best mode; initialise outBestCU to 2Nx2N */
>                      outBestCU = m_interCU_2Nx2N[depth];
> -                    tempYuv = m_modePredYuv[0][depth];
> -                    m_modePredYuv[0][depth] = m_bestPredYuv[depth];
> -                    m_bestPredYuv[depth] = tempYuv;
> +                    std::swap(m_bestPredYuv[depth],
> m_modePredYuv[0][depth]);
>                  }
>
>                  /* Compute Rect costs */
> @@ -475,18 +460,12 @@
>                      if (m_interCU_Nx2N[depth]->m_totalRDCost <
> outBestCU->m_totalRDCost)
>                      {
>                          outBestCU = m_interCU_Nx2N[depth];
> -
> -                        tempYuv = m_modePredYuv[1][depth];
> -                        m_modePredYuv[1][depth] = m_bestPredYuv[depth];
> -                        m_bestPredYuv[depth] = tempYuv;
> +                        std::swap(m_bestPredYuv[depth],
> m_modePredYuv[1][depth]);
>                      }
>                      if (m_interCU_2NxN[depth]->m_totalRDCost <
> outBestCU->m_totalRDCost)
>                      {
>                          outBestCU = m_interCU_2NxN[depth];
> -
> -                        tempYuv = m_modePredYuv[2][depth];
> -                        m_modePredYuv[2][depth] = m_bestPredYuv[depth];
> -                        m_bestPredYuv[depth] = tempYuv;
> +                        std::swap(m_bestPredYuv[depth],
> m_modePredYuv[2][depth]);
>                      }
>                  }
>
> @@ -506,13 +485,8 @@
>                      if (bestMergeCost < bestCost)
>                      {
>                          outBestCU = m_bestMergeCU[depth];
> -                        tempYuv = m_modePredYuv[3][depth];
> -                        m_modePredYuv[3][depth] = m_bestPredYuv[depth];
> -                        m_bestPredYuv[depth] = tempYuv;
> -
> -                        tempYuv = m_bestRecoYuv[depth];
> -                        m_bestRecoYuv[depth] = m_bestMergeRecoYuv[depth];
> -                        m_bestMergeRecoYuv[depth] = tempYuv;
> +                        std::swap(m_bestPredYuv[depth],
> m_modePredYuv[3][depth]);
> +                        std::swap(m_bestRecoYuv[depth],
> m_bestMergeRecoYuv[depth]);
>                      }
>                  }
>
> @@ -547,13 +521,8 @@
>                          if (intraInInterCost < bestCost)
>                          {
>                              outBestCU = m_intraInInterCU[depth];
> -                            tempYuv = m_modePredYuv[5][depth];
> -                            m_modePredYuv[5][depth] =
> m_bestPredYuv[depth];
> -                            m_bestPredYuv[depth] = tempYuv;
> -
> -                            TComYuv* tmpPic = m_bestRecoYuv[depth];
> -                            m_bestRecoYuv[depth] = m_tmpRecoYuv[depth];
> -                            m_tmpRecoYuv[depth] = tmpPic;
> +                            std::swap(m_bestPredYuv[depth],
> m_modePredYuv[5][depth]);
> +                            std::swap(m_bestRecoYuv[depth],
> m_tmpRecoYuv[depth]);
>                          }
>                      }
>                  }
> @@ -562,13 +531,8 @@
>                      if (m_bestMergeCU[depth]->m_sa8dCost <
> outBestCU->m_totalRDCost)
>                      {
>                          outBestCU = m_bestMergeCU[depth];
> -                        tempYuv = m_modePredYuv[3][depth];
> -                        m_modePredYuv[3][depth] = m_bestPredYuv[depth];
> -                        m_bestPredYuv[depth] = tempYuv;
> -
> -                        tempYuv = m_bestRecoYuv[depth];
> -                        m_bestRecoYuv[depth] = m_bestMergeRecoYuv[depth];
> -                        m_bestMergeRecoYuv[depth] = tempYuv;
> +                        std::swap(m_bestPredYuv[depth],
> m_modePredYuv[3][depth]);
> +                        std::swap(m_bestRecoYuv[depth],
> m_bestMergeRecoYuv[depth]);
>                      }
>                      else if (outBestCU->getPredictionMode(0) ==
> MODE_INTER)
>                      {
> @@ -591,13 +555,8 @@
>                      if (m_bestMergeCU[depth]->m_sa8dCost <
> outBestCU->m_totalRDCost)
>                      {
>                          outBestCU = m_bestMergeCU[depth];
> -                        tempYuv = m_modePredYuv[3][depth];
> -                        m_modePredYuv[3][depth] = m_bestPredYuv[depth];
> -                        m_bestPredYuv[depth] = tempYuv;
> -
> -                        tempYuv = m_bestRecoYuv[depth];
> -                        m_bestRecoYuv[depth] = m_bestMergeRecoYuv[depth];
> -                        m_bestMergeRecoYuv[depth] = tempYuv;
> +                        std::swap(m_bestPredYuv[depth],
> m_modePredYuv[3][depth]);
> +                        std::swap(m_bestRecoYuv[depth],
> m_bestMergeRecoYuv[depth]);
>                      }
>                      else if (outBestCU->getPredictionMode(0) ==
> MODE_INTER)
>                      {
> @@ -630,13 +589,8 @@
>              else
>              {
>                  outBestCU = m_bestMergeCU[depth];
> -                tempYuv = m_modePredYuv[3][depth];
> -                m_modePredYuv[3][depth] = m_bestPredYuv[depth];
> -                m_bestPredYuv[depth] = tempYuv;
> -
> -                tempYuv = m_bestRecoYuv[depth];
> -                m_bestRecoYuv[depth] = m_bestMergeRecoYuv[depth];
> -                m_bestMergeRecoYuv[depth] = tempYuv;
> +                std::swap(m_bestPredYuv[depth], m_modePredYuv[3][depth]);
> +                std::swap(m_bestRecoYuv[depth],
> m_bestMergeRecoYuv[depth]);
>              }
>
>              if (m_param->rdLevel > 0) // checkDQP can be done only after
> residual encoding is done
> @@ -856,23 +810,15 @@
>              if (tempCost < bestCost)
>              {
>                  outBestCU = outTempCU;
> -                tempYuv = m_tmpRecoYuv[depth];
> -                m_tmpRecoYuv[depth] = m_bestRecoYuv[depth];
> -                m_bestRecoYuv[depth] = tempYuv;
> -                tempYuv = m_tmpPredYuv[depth];
> -                m_tmpPredYuv[depth] = m_bestPredYuv[depth];
> -                m_bestPredYuv[depth] = tempYuv;
> +                std::swap(m_bestRecoYuv[depth], m_tmpRecoYuv[depth]);
> +                std::swap(m_bestPredYuv[depth], m_tmpPredYuv[depth]);
>              }
>          }
>          else
>          {
>              outBestCU = outTempCU;
> -            tempYuv = m_tmpRecoYuv[depth];
> -            m_tmpRecoYuv[depth] = m_bestRecoYuv[depth];
> -            m_bestRecoYuv[depth] = tempYuv;
> -            tempYuv = m_tmpPredYuv[depth];
> -            m_tmpPredYuv[depth] = m_bestPredYuv[depth];
> -            m_bestPredYuv[depth] = tempYuv;
> +            std::swap(m_bestRecoYuv[depth], m_tmpRecoYuv[depth]);
> +            std::swap(m_bestPredYuv[depth], m_tmpPredYuv[depth]);
>          }
>      }
>
> diff -r 644773b85329 -r a3f4317f4acd source/encoder/framefilter.cpp
> --- a/source/encoder/framefilter.cpp    Wed Jul 09 13:55:42 2014 +0530
> +++ b/source/encoder/framefilter.cpp    Wed Jul 09 18:27:26 2014 +0900
> @@ -480,9 +480,7 @@
>      {
>          for (; z <= y; z++)
>          {
> -            void* swap = sum0;
> -            sum0 = sum1;
> -            sum1 = (int(*)[4])swap;
> +            std::swap(sum0, sum1);
>              for (int x = 0; x < width; x += 2)
>              {
>                  primitives.ssim_4x4x2_core(&pix1[(4 * x + (z *
> stride1))], stride1, &pix2[(4 * x + (z * stride2))], stride2, &sum0[x]);
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20140709/6cf8b785/attachment-0001.html>


More information about the x265-devel mailing list