Index: /CKEditor/branches/features/pasting/_source/core/htmlparser/fragment.js
===================================================================
--- /CKEditor/branches/features/pasting/_source/core/htmlparser/fragment.js	(revision 4505)
+++ /CKEditor/branches/features/pasting/_source/core/htmlparser/fragment.js	(revision 4506)
@@ -265,5 +265,5 @@
 		parser.onTagClose = function( tagName )
 		{
-			var index = 0,
+			var index = pendingInline.length - 1,
 				pendingAdd = [],
 				candidate = currentNode;
@@ -274,11 +274,5 @@
 				// it will continue after the closing tag.
 				if ( !candidate._.isBlockLike )
-				{
-					pendingInline.unshift( candidate );
-
-					// Increase the index, so it will not get checked again in
-					// the pending list check that follows.
-					index++;
-				}
+					pendingInline.push( candidate );
 
 				// This node should be added to it's parent at this point. But,
@@ -314,11 +308,8 @@
 			// the pending elements.(#3862)
 			else
-			{
-				pendingInline.splice( 0, index );
-				index = 0;
-			}
-
-			// Check if there is any pending tag to be closed.
-			for ( ; index < pendingInline.length ; index++ )
+				pendingInline.length = index + 1;
+
+			// Check if there is one pending tag to be closed.
+			for ( ; index >= 0 ; index-- )
 			{
 				// If found, just remove it from the list.
@@ -326,7 +317,5 @@
 				{
 					pendingInline.splice( index, 1 );
-
-					// Decrease the index so we continue from the next one.
-					index--;
+					break;
 				}
 			}
@@ -451,5 +440,6 @@
 				var writer = new CKEDITOR.htmlParser.basicWriter();
 				this.writeChildrenHtml.call( this, writer, filter, true );
-				this.children = new CKEDITOR.htmlParser.fragment.fromHtml( writer.getHtml() ).children;
+				var html = writer.getHtml();
+				this.children = new CKEDITOR.htmlParser.fragment.fromHtml( html ).children;
 				isChildrenFiltered = 1;
 			};
