1. Си / Говнокод #13492

    +122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    #if defined(REG_R1) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R1,REG_R1)
    #else
    # define R1 (BaseReg->rR1)
    #endif
    
    #if defined(REG_R2) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R2,REG_R2)
    #else
    # define R2 (BaseReg->rR2)
    #endif
    
    #if defined(REG_R3) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R3,REG_R3)
    #else
    # define R3 (BaseReg->rR3)
    #endif
    
    #if defined(REG_R4) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R4,REG_R4)
    #else
    # define R4 (BaseReg->rR4)
    #endif
    
    #if defined(REG_R5) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R5,REG_R5)
    #else
    # define R5 (BaseReg->rR5)
    #endif
    
    #if defined(REG_R6) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R6,REG_R6)
    #else
    # define R6 (BaseReg->rR6)
    #endif
    
    #if defined(REG_R7) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R7,REG_R7)
    #else
    # define R7 (BaseReg->rR7)
    #endif
    
    ...

    Исходник GHC
    https://github.com/ghc/ghc/blob/master/includes/stg/Regs.h#L147

    j123123, 27 Июля 2013

    Комментарии (39)
  2. Куча / Говнокод #13491

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    slowCallPattern (P: P: P: P: P: P: _) = (fsLit "stg_ap_pppppp", 6)
    slowCallPattern (P: P: P: P: P: _) = (fsLit "stg_ap_ppppp", 5)
    slowCallPattern (P: P: P: P: _) = (fsLit "stg_ap_pppp", 4)
    slowCallPattern (P: P: P: V: _) = (fsLit "stg_ap_pppv", 4)
    slowCallPattern (P: P: P: _) = (fsLit "stg_ap_ppp", 3)
    slowCallPattern (P: P: V: _) = (fsLit "stg_ap_ppv", 3)
    slowCallPattern (P: P: _) = (fsLit "stg_ap_pp", 2)
    slowCallPattern (P: V: _) = (fsLit "stg_ap_pv", 2)
    slowCallPattern (P: _) = (fsLit "stg_ap_p", 1)
    slowCallPattern (V: _) = (fsLit "stg_ap_v", 1)
    slowCallPattern (N: _) = (fsLit "stg_ap_n", 1)
    slowCallPattern (F: _) = (fsLit "stg_ap_f", 1)
    slowCallPattern (D: _) = (fsLit "stg_ap_d", 1)
    slowCallPattern (L: _) = (fsLit "stg_ap_l", 1)
    slowCallPattern (V16: _) = (fsLit "stg_ap_v16", 1)
    slowCallPattern [] = (fsLit "stg_ap_0", 0)

    Исходник GHC
    https://github.com/ghc/ghc/blob/master/compiler/codeGen/StgCmmArgRep.hs#L120

    j123123, 27 Июля 2013

    Комментарии (5)
  3. Си / Говнокод #13490

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    void mb_sim_pix(uchar* IN, uchar* OUT, int *WH, int *bSize, int *A, int *pSize, float *threshold){
    	int pos = mb_calc_pos(A, WH, pSize);
    	int nPos;
    	int i, n;
    	int B[2];
    		
    	for(n = 0; n < 4; n++){
    		
    		switch(n){
    			case 0:
    				B[0] = A[0] + 1;
    				B[1] = A[1];
    			
    			case 1:
    				B[0] = A[0];
    				B[1] = A[1] - 1;
    			
    			case 2:
    				B[0] = A[0];
    				B[1] = A[1] + 1;
    			
    			case 3:
    				B[0] = A[0] - 1;
    				B[1] = A[1];
    		}
    		
    		if(	B[0] >= 0 && B[0] < WH[0] &&
    			B[1] >= 0 && B[1] < WH[1]){
    			nPos = mb_calc_pos(B, WH, pSize);
    			if(mb_val_pix(OUT, &nPos, pSize) == 0){
    				if(mb_sim_pack(IN, &pos, &nPos, pSize) >= *threshold){
    					for(i = 0; i < *pSize; i++) OUT[nPos + i] = IN[nPos + i];
    					mb_sim_pix(IN, OUT, WH, bSize, B, pSize, threshold);
    				}
    			}
    		}
    	}
    }

    Тоже самое через if работает, а через switch проваливается на значении 0 все итерации. Почему?

    Stertor, 27 Июля 2013

    Комментарии (62)
  4. C++ / Говнокод #13488

    +75

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    int i, n;
    for(n = 0; n < 3; n++)
    {
       switch(n){
             case 0:
                    n+=i;
             case 1:
                    n-=i;
             case 2:
                    n*=i;
       }
    }

    Написал это, встал и хорошенько вымыл руки с мылом.

    http://programmersforum.ru/showthread.php?t=241288

    Stertor, 26 Июля 2013

    Комментарии (17)
  5. C++ / Говнокод #13487

    +12

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    struct c_test
    {
      int value;
      
      c_test(void)
      {
        (void)new (this) c_test (10);
      }
      
      c_test(int v)
      {
        value = v;
      }
    };

    LispGovno, 26 Июля 2013

    Комментарии (18)
  6. PHP / Говнокод #13486

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $rsResult = CIBlockSection::GetList(array("SORT" => "ASC"), array("IBLOCK_ID" => $arResult['IBLOCK_ID']), false, array("UF_TEMPLATE_TYPE"));
    while ($ar = $rsResult->GetNext()) {
        if ($ar["UF_TEMPLATE_TYPE"]) {
            var_dump($ar["UF_TEMPLATE_TYPE"]);
        }
    }

    maeln0r, 26 Июля 2013

    Комментарии (1)
  7. Java / Говнокод #13485

    +68

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    LineDir ld = ild.next();
    int y = ld.getYDirAdj(), h = ld.getHeightDir();				
    PDFTextStripperByArea pts = new PDFTextStripperByArea();
    pts.addRegion("column3", new Rectangle(470,y,70,h));
    pts.addRegion("column4", new Rectangle(540,y,50,h));
    pts.extractRegions(page);
    try {
              int g = 0;
              String column3 = pts.getTextForRegion("column3").trim();
              String column4 = pts.getTextForRegion("column4").trim();
              if (column3.isEmpty()) {
                        g = 1/0;
              }
              g = Integer.valueOf(column4);					
    } catch(Exception e) {
             ild.remove();
    }

    Парсил pdf ничего лучше чем проверка нахождения 1)непустой строки(11) и 2)числа(14) в выбраных областях не нашел (в этих строках всегда есть эти столбцы). 2 если там не число то будет ошибка а в 1 сделал что бы ошибка за компанию была )

    Mooncrafter, 26 Июля 2013

    Комментарии (0)
  8. C++ / Говнокод #13484

    +8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    #include <pthread.h>
    template<class T = long long>
    class AtomicCounter
    {
        public:
            explicit AtomicCounter( T value = 0 ): _count( value ) { pthread_spin_init( &_lock, PTHREAD_PROCESS_PRIVATE );};
            ~AtomicCounter()  { pthread_spin_destroy( &_lock );    };
    
            T operator++(int) volatile {  return interlockFetchAndAdd( 1 );      };
            T operator--(int) volatile {  return interlockFetchAndAdd( -1 );     };
            T operator() ()   volatile {  return interlockFetchAndAdd( 0 );      }
    
        private:
            volatile T    _count;
            pthread_spinlock_t _lock;
    
            T interlockFetchAndAdd( int delta ) volatile
            {
                T x = 0;
                pthread_spin_lock( &_lock );
                x = _count;
                _count += delta;
                pthread_spin_unlock(&_lock);
                return x;
            }
    };

    Принцип наименьшего удивления, говорите

    roman-kashitsyn, 26 Июля 2013

    Комментарии (51)
  9. C++ / Говнокод #13483

    +14

    1. 1
    2. 2
    3. 3
    4. 4
    std::string buf_str = str;
    buf_str.erase( 0, strBlobFsParam.size() + 1 );
    buf_str.erase( buf_str.begin(), find_if(buf_str.begin(), buf_str.end(), not1( ptr_fun<int, int>(isspace) ) ) );
    buf_str.erase( find_if( buf_str.rbegin(), buf_str.rend(), not1( ptr_fun<int, int>(isspace) ) ).base(), buf_str.end() );

    trim головного мозга

    roman-kashitsyn, 26 Июля 2013

    Комментарии (7)
  10. Java / Говнокод #13482

    +111

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    public class PmsUtil {
    	
    	public static boolean allowViewFolder(IFolder folder) {
    		return isIntersected(folder.getPermissions(), getUserPms());
    	}
    
    	private static Set<Permission> getUserPms() {
    		return LoginController.get().getUser().getRole().getPermissions();
    	}
    
    	private static boolean isIntersected(Set<Permission> pmsSetA, Set<Permission> pmsSetB) {
    		for(Permission pms : pmsSetB) {
    			if(pmsSetA.contains(pms)) {
    				return true;
    			}
    		}
    		return false;
    	}
    
    	
    }

    К слову об именах переменных... любил мой предшественник делать нестандартные сокращения.

    someone, 26 Июля 2013

    Комментарии (10)