From 822954d29add918fd55a728b2c62e257e650b954 Mon Sep 17 00:00:00 2001 From: tomByrer Date: Thu, 30 Jan 2014 07:44:13 +0000 Subject: [PATCH] Fixes #213 - faster rgb to hex transforms. --- History.md | 1 + lib/colors/rgb-to-hex.js | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/History.md b/History.md index 229fab04..20c49f46 100644 --- a/History.md +++ b/History.md @@ -12,6 +12,7 @@ * Fixed issue [#165](https://github.com/GoalSmashers/clean-css/issues/165) - extra space after trailing parenthesis. * Fixed issue [#186](https://github.com/GoalSmashers/clean-css/issues/186) - strip unit from 0rem. * Fixed issue [#207](https://github.com/GoalSmashers/clean-css/issues/207) - bug in parsing protocol `@import`s. +* Fixed issue [#213](https://github.com/GoalSmashers/clean-css/issues/213) - faster rgb to hex transforms. [2.0.7 / 2014-01-16](https://github.com/GoalSmashers/clean-css/compare/v2.0.6...v2.0.7) ================== diff --git a/lib/colors/rgb-to-hex.js b/lib/colors/rgb-to-hex.js index d235289b..479e6208 100644 --- a/lib/colors/rgb-to-hex.js +++ b/lib/colors/rgb-to-hex.js @@ -2,14 +2,8 @@ module.exports = function RGBToHex(data) { return { process: function() { return data.replace(/rgb\((\d+),(\d+),(\d+)\)/g, function(match, red, green, blue) { - var redAsHex = parseInt(red, 10).toString(16); - var greenAsHex = parseInt(green, 10).toString(16); - var blueAsHex = parseInt(blue, 10).toString(16); - - return '#' + - ((redAsHex.length == 1 ? '0' : '') + redAsHex) + - ((greenAsHex.length == 1 ? '0' : '') + greenAsHex) + - ((blueAsHex.length == 1 ? '0' : '') + blueAsHex); + // Credit: Asen http://jsbin.com/UPUmaGOc/2/edit?js,console + return '#' + ('00000' + (red << 16 | green << 8 | blue).toString(16)).slice(-6); }); } }; -- 2.34.1