Index: wordpress/wp-includes/taxonomy.php
===================================================================
--- wordpress/wp-includes/taxonomy.php	(revision 6340)
+++ wordpress/wp-includes/taxonomy.php	(working copy)
@@ -1318,6 +1318,21 @@
 	return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
 }
 
+// enable or disable term count deferring
+// if no value is supplied, the current value of the defer setting is returned
+function wp_defer_term_counting($defer=NULL) {
+	static $_defer = false;
+	
+	if ( is_bool($defer) ) {
+		$_defer = $defer;
+		// flush any deferred counts
+		if ( !$defer )
+			wp_update_term_count( NULL, NULL, true );
+	}
+	
+	return $_defer;
+}
+
 /**
  * wp_update_term_count() - Updates the amount of terms in taxonomy
  * 
@@ -1335,15 +1350,35 @@
  * @param string $taxonomy The context of the term.
  * @return bool If no terms will return false, and if successful will return true.
  */
-function wp_update_term_count( $terms, $taxonomy ) {
-	global $wpdb;
+function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) {
+	static $_deferred = array();
 
+	if ( $do_deferred ) {
+		foreach ( array_keys($_deferred) as $tax ) {
+			wp_update_term_count_now( $_deferred[$tax], $tax );
+			unset( $_deferred[$tax] );
+		}
+	}
+
 	if ( empty($terms) )
 		return false;
 
 	if ( !is_array($terms) )
 		$terms = array($terms);
 
+	if ( wp_defer_term_counting() ) {
+		if ( !isset($_deferred[$taxonomy]) )
+			$_deferred[$taxonomy] = array();
+		$_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) );
+		return true;
+	}
+	
+	return wp_update_term_count_now( $terms, $taxonomy );
+}
+
+function wp_update_term_count_now( $terms, $taxonomy ) {
+	global $wpdb;
+
 	$terms = array_map('intval', $terms);
 
 	$taxonomy = get_taxonomy($taxonomy);
