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

2014-07-09 Thread Satoshi Nakagawa
# HG changeset patch
# User Satoshi Nakagawa nakagawa...@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.cppWed Jul 09 
13:55:42 2014 +0530
+++ b/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cppWed 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
--- 

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

2014-07-09 Thread Deepthi Nandakumar
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 nakagawa...@oki.com
wrote:

 # HG changeset patch
 # User Satoshi Nakagawa nakagawa...@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.cppWed Jul 09
 13:55:42 2014 +0530
 +++ b/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cppWed 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 = 

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

2014-07-09 Thread Derek Buitenhuis
On 7/9/2014 11:16 AM, Deepthi Nandakumar wrote:
 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.

I tried to ask about this before to no avail: What compilers and how?

STL portability has not been an issue for a very long time.

- Derek
___
x265-devel mailing list
x265-devel@videolan.org
https://mailman.videolan.org/listinfo/x265-devel